Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Walkspeed On Click?

So I am working on a script that when you click a part your walkspeed hits 0. and your jump power is 0. Having a bit of troubles.

group = script.Parent.Parent

function onClicked(part)
	script.Parent.Transparency = 1
	group.CLOSED.Transparency = 0
    Player.Humanoid.WalkSpeed = 0
    Player.Humanoid.JumpPower = 0
end

script.Parent.ClickDetector.MouseClick:connect (onClicked)

1 comment

0

Don't put a space between connect and (onClicked)

1 answer

✓ Accepted answer

Well, basically,

function onClicked([THIS IS THE PLAYER]) 

that section there is a return for the player, you had 'Part' there and in your script you were calling Player.Humanoid which doesn't exist. So we changed that to Player.

Now we need to get the player's Character. which can be achieved by doing

Player.Character

But it's safe to check if the player's character exists before doing anything with it.

local Character = Player.Character or player.CharacterAdded:wait()

But we only use that when Player is being given.

This is your script fixed.

local group = script.Parent.Parent

function onClicked(Player)
local Character = Player.Character or player.CharacterAdded:wait()

    script.Parent.Transparency = 1
    group.CLOSED.Transparency = 0

    Character.Humanoid.WalkSpeed = 0
   Character.Humanoid.JumpPower = 0
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

Hoped this helped :)

This discussion is preserved as it was. New answers, comments, and votes are closed.