Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What's the problem in the script?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I put this code in a LocalScript, and it'll run the script once the player touches the Brick with the script in it. Wheres my problem? I'm new to scripting...

1local character = game.Players.LocalPlayer.Character
2 
3script.Parent.Touched:connect(function()
4    if character.Humanoid.WalkSpeed == 16 then
5        character.Humanoid.WalkSpeed = 20
6    else
7        character.Humanoid.WalkSpeed = 20
8    end
9end)
0
Just noticed I don't need line 6 and 7 :/ DeAigle 7 — 9y
0
Is there a reason you are using a LocalScript rather than a regular script? ModZombie 70 — 9y

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

Accessing LocalPlayer is for when the script is running on that player's computer, inside things like GUIs and tools. In a server script, it doesn't mean anything in particular. Instead, you would need to get the character from the part which touched the object, like this:

1script.Parent.Touched:connect(function(hit)
2    local character=hit.Parent
3    if character:FindFirstChild("Humanoid")then
4        if character.Humanoid.WalkSpeed==16 then
5            character.Humanoid.WalkSpeed=20
6        end
7    end
8end)
Ad

Answer this question