I have a LocalScript in StarterCharacterScripts that’s supposed to change the character’s state when clicked, but for some reason when I click, nothing happens at all & there are no errors. I’ve searched for like 2 hours and can’t find anything about this, thank you.
Code:
--// Variables
local Player = game.Players.LocalPlayer
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local Root = Character:WaitForChild("HumanoidRootPart")
local uis = game:GetService("UserInputService")
local physics = false
Humanoid.HipHeight = -0.5
--// Event
uis.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then return end
if input == Enum.UserInputType.MouseButton1 then
if physics == false then
physics = true
Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
else
physics = false
Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
end
end
end)
Your script contained: if input == Enum.UserInputType.MouseButton1 then
The change was: if input.UserInputType == Enum.UserInputType.MouseButton1 then
The key thing to remember for any use of UserInputService’s InputObject is to check the UserInputType because that will verify if your type of input matches, such as a keyboard or mouse.
There’s a lot more to digest about UserInputService, but you should be okay with just that.
--// Variables
local Player = game.Players.LocalPlayer
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local Root = Character:WaitForChild("HumanoidRootPart")
local uis = game:GetService("UserInputService")
local physics = false
Humanoid.HipHeight = -0.5
--// Event
uis.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if physics == false then
physics = true
Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
else
physics = false
Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
end
end
end)
I’m not sure how or why this works but it did, I read over yours and mine and the only difference I could notice was that an empty line was removed, I’m soo confused but thanks!
My bad, I was in a hurry when I wrote my solution. I can explain a bit more about what changed.
Your script contained: if input == Enum.UserInputType.MouseButton1 then
The change was: if input.UserInputType == Enum.UserInputType.MouseButton1 then
The key thing to remember for any use of UserInputService’s InputObject is to check the UserInputType because that will verify if your type of input matches, such as a keyboard or mouse.
There’s a lot more to digest about UserInputService, but you should be okay with just that.