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?
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:
local BasePlate = script.Parent -- Our Trigger function onTouch(Brick) -- Declared a onTouch function local Player = game:GetService'Players'.LocalPlayer -- Our Player if (Player ~= nil) then -- Check to see if it exists Player.Character.Humanoid.WalkSpeed = 32 -- Changing the walkspeed end -- ending our if statement end -- ending our funtion BasePlate.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.
local BasePlate = script.Parent -- Our Trigger function onTouch(Brick) -- Declared a onTouch function local Player = Brick.Parent:findFirstChild("Humanoid") -- Our Player if (Player ~= nil) then -- Check to see if it exists Player.WalkSpeed = 32 -- Changing the walkspeed end -- ending our if statement end -- ending our funtion BasePlate.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.
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.
local speed = 10 game.Players.PlayerAdded:connect(function( user) --newly added player == `user` user.CharacterAdded:connect(function( char ) --user's character(workspace>user) loaded local humanoid = char.Humanoid if humanoid then humanoid.WalkSpeed = speed end; end); end);