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

Local Script won't change WalkSpeed?

Asked by 2 years ago

I have no idea why this is happening but I made it so they can't walk (and jump) when they join (on the server) but when they press the start button they can move again (on the client).

Here are the scripts:

Server Script:

game.Players.PlayerAdded:Connect(function(plr)

    local character = plr.Character or plr.CharacterAdded:Wait()

    character.Humanoid.WalkSpeed = 0
    character.Humanoid.JumpPower = 0

    local leaderstats = Instance.new("Folder")
    leaderstats.Parent = plr
    leaderstats.Name = "leaderstats"

    local Wins = Instance.new("IntValue")
    Wins.Parent = leaderstats
    Wins.Name = "Wins"

end)

Local Script:

local localPlayer = game.Players.LocalPlayer
local humanoid = localPlayer.CharacterAdded:Wait():WaitForChild("Humanoid")
script.Parent.MouseButton1Click:Connect(function(plr)
    script.Parent.Parent.Parent.Enabled = false
    if plr == localPlayer then
        humanoid.WalkSpeed = 16
        humanoid.JumpHeight = 7.2
    end
end)

Once again this doesn't make sense to me as I'm pretty sure this should work.

0
Hi can't you just go to game settings under world change the speed and jump height?? I don't understand what you are trying to make with this. theking66hayday 841 — 2y
0
Sorry for the misunderstanding but I'm trying to make it where if they press a button they get to move but when they first join they are still aydenwilson819 25 — 2y

4 answers

Log in to vote
0
Answered by 2 years ago

It's because on the server they're still set to 0. The server is overwriting the clients when it updates them about how the game is supposed to be currently playing out since according to the server, they're still supposed to be unable to walk or jump. Clients themselves can't modify any physical information the server has so you have to have the client let the server know. You're gonna want to use RemoteEvents to tell the server when the player presses a button so the server itself can set them back to their correct speed.

0
I just tried it and I don't know if it works yet because it doesn't even register the mousebutton1click function, I even put a print right after the function and nothing came out in the output. So it has something to do with the MouseButton1Click function. aydenwilson819 25 — 2y
0
I fixed it all I did was take the textbutton out the frame but still in the screengui and it works! aydenwilson819 25 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

There is a wait in your local script next the wait for child in your humanoid variable

0
There's nothing wrong about it aydenwilson819 25 — 2y
Log in to vote
0
Answered by 2 years ago

A few things here, you don't need all of that humanoid variable, and you don't need to check if the thing clicking is the localPlayer, it's a local script.

local localPlayer = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent.Parent.Enabled = false
    localPlayer.Character.Humanoid.WalkSpeed = 16
    localPlayer.Character.Humanoid.JumpHeight = 7.2
end)
0
It still doesn't work aydenwilson819 25 — 2y
Log in to vote
0
Answered by 2 years ago

It also Happened to me while making a super speed script even I was using local scripts.

0
I think it said trying to Index WalkSpeed with Nil? tosinidowu -2 — 2y

Answer this question