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

How Do I make a script to change everyone's walkspeed?

Asked by 9 years ago

So, I want so change the Walkspeed of everyone that joins my game. I think I know how to do it but I don't know where the players are located on the workspace. I tried game.Workspace.Player1 but nothing...And I tried game.Workspace.LocalPlayer and nothing too... so can someone help me?

2 answers

Log in to vote
1
Answered by
KenzaXI 166
9 years ago

I'll Explain the script, So you understand what to do next time; Don't use game.Players.LocalPlayer Because that's a technique which only works well in a LocalScript. So Instead we use : game:GetService'Players'.LocalPlayer And now that that's done, I'll Explain it, We don't Define Players from the Workspace unless you want to Define specific players, but since you want everyone who touches this part to go faster we'll use this method. Ok Here's our script:

1local BasePlate = script.Parent -- Our Trigger
2function onTouch(Brick) -- Declared a onTouch function
3    local Player = game:GetService'Players'.LocalPlayer -- Our Player
4    if (Player ~= nil) then -- Check to see if it exists
5        Player.Character.Humanoid.WalkSpeed = 32 -- Changing the walkspeed
6    end -- ending our if statement
7end -- ending our funtion
8BasePlate.Touched:connect(onTouch) -- connecting out function to our Trigger

there is our another way which is faster, I don't need to Explain it because it's exactly the same but just less lines of Code.

1local BasePlate = script.Parent -- Our Trigger
2function onTouch(Brick) -- Declared a onTouch function
3    local Player =
4    Brick.Parent:findFirstChild("Humanoid") -- Our Player
5    if (Player ~= nil) then -- Check to see if it exists
6        Player.WalkSpeed = 32 -- Changing the walkspeed
7    end -- ending our if statement
8end -- ending our funtion
9BasePlate.Touched:connect(onTouch) -- connecting out function to our Trigger

Hope I helped, If it worked Mark as answer :D Also if you need any help or if it doesn't work just comment below and I'll be happy to help.

Ad
Log in to vote
1
Answered by
ImageLabel 1541 Moderation Voter
9 years ago

LocalPlayer is a property of the Players service... therefore ...not located in the workspace, and can only be used by LocalScripts.

You'd probably be better off using a server script though.

01local speed = 10
02 
03game.Players.PlayerAdded:connect(function( user)
04    --newly added player == `user`
05 
06    user.CharacterAdded:connect(function( char )
07        --user's character(workspace>user) loaded
08        local humanoid = char.Humanoid
09 
10        if humanoid then
11            humanoid.WalkSpeed = speed
12        end;
13    end);
14end);

Answer this question