Ok so for context I'm making a script where the intended thing to happen is when you press the button it sets your walkspeed to 0. The catch is, the button is on yourself, aka its a starter character button. This is the script:
local OnButton = script.Parent function turnOff(plr) if game.StarterPlayer.StarterCharacter.Humanoid.WalkSpeed == 16 then game.StarterPlayer.StarterCharacter.Humanoid.WalkSpeed = 0 and OnButton.BrickColor == BrickColor.new("Smoky grey") end end OnButton.ClickDetector.MouseClick:Connect(turnOff)
So how do I go about fixing this script so it is working and clickable? Because right now what it does if you try to click the one on yourself it does nothing, does not consider it a button. But with another player, the clicking icon shows up, but it does not do the thing I wanted it to. Any help?
If you want this to work, first realize that you're editing the StarterCharacter
, not the player's current character. This "current character" can be accessed by doing Player.Character.
Since you have a ClickDetector, this will be relatively simple in converting.
local OnButton = script.Parent function turnOff(plr) -- plr.Character refers to the current player we have, and not the StarterCharacter model. if plr.Character.Humanoid.WalkSpeed == 16 then -- There was an issue with you using "and" to try and apply assign multiple properties. You don't need to do that. You can put them all on separate lines. plr.Character.Humanoid.WalkSpeed = 0 OnButton.BrickColor = BrickColor.new("Smoky grey") end end OnButton.ClickDetector.MouseClick:Connect(turnOff)