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...

local character = game.Players.LocalPlayer.Character

script.Parent.Touched:connect(function()
    if character.Humanoid.WalkSpeed == 16 then
        character.Humanoid.WalkSpeed = 20
    else
        character.Humanoid.WalkSpeed = 20
    end
end)
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:

script.Parent.Touched:connect(function(hit)
    local character=hit.Parent
    if character:FindFirstChild("Humanoid")then
        if character.Humanoid.WalkSpeed==16 then
            character.Humanoid.WalkSpeed=20
        end
    end
end)
Ad

Answer this question