-- Handles behaviours

local function characterTouchedBrick(partTouched)
	local behaviours = partTouched:FindFirstChild("Behaviours")
	if behaviours ~= nil then
		behaviours = behaviours:GetChildren()
		for i = 1, #behaviours do
			if behaviours[i].Value == true then
				game.ReplicatedStorage.RemoteEvents.ExecuteBehaviour:FireServer(player.Character, partTouched, behaviours[i].Name)

				if string.find(behaviours[i].Name, "Kill") then
					SmoothDie()
				end

			end
		end
	end
end

function characterAdded(newCharacter)
	ResetGame()
	bindFuc:Invoke(true)
	character = player.Character
	humanoid = character:WaitForChild("Humanoid")
	animator = humanoid:WaitForChild("Animator")
	humanoid.Touched:connect(characterTouchedBrick)
	humanoid.Died:connect(OnDie)
	SetWalkSpeed(0)

	local splashScreen = player.PlayerGui:WaitForChild("StartScreen")

	if UserInputService.TouchEnabled == false then
		if UserInputService.GamepadEnabled then
			splashScreen.StartInstructions.StartLabel.Text = "Press Space or Gamepad A Button to Start"
		else
			splashScreen.StartInstructions.StartLabel.Text = "Press Space to Start"
		end

	end
end




local function MoveAction(actionName, inputState, inputObject)
	if(not startGame) then
		return
	end

	if inputState == Enum.UserInputState.Begin then
		if inputObject.KeyCode == Enum.KeyCode.Left then
			left = -1
			moveDir = -1
		elseif inputObject.KeyCode == Enum.KeyCode.Right then
			right = 1
			moveDir = 1
		end
		SetWalkSpeed(moveSpeed)
	elseif inputState == Enum.UserInputState.End then
		if inputObject.KeyCode == Enum.KeyCode.Left then
			left = 0
		elseif inputObject.KeyCode == Enum.KeyCode.Right then
			right = 0
		end
		moveDir = left + right
		if moveDir == 0 then
			SetWalkSpeed(0) 
		end

	end
end
