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

WalkSpeed value isn't changing?

Asked by
Jxdenx 45
5 years ago
script.Parent.TextButton2.MouseButton1Click:Connect(function()
    script.Parent.Visible = false
    for i = 3, 0, -1 do
            ChangeText("Start constantly running "..i, "Msgs")
            wait(1)
        end
        for _,v in pairs(game.Players:GetChildren()) do
             if v.Character.Humanoid.WalkSpeed > 16 and v.Settings.Playing.Value == true then
            v.Settings.Ran.Value = true
        end
            wait()
                if v.Settings.Ran.Value == true then
                    v.Character.Humanoid.Health = 0

                end
        end

script.Parent.Visible = true
        end)

When a players walkspeed value is greater than 16, it's supposed to change the boolvalue to true then kill the player, but when the player runs and the value changes to 80, the boolvalue doesn't set to true.

I've tested by changing the script to set boolvalue to true when the player's walkspeed is 16, it seems to work.

0
Looks like you're trying to affect other players from a local script. Are you trying to kill them all from the local script? User#24403 69 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Since you want to affect all players, you'll need to use a Remote Event, meaning you need BOTH a LocalScript and a ServerScript

I'm not sure what the function "ChangeText" is, but otherwise, your code should be structured like so:

Local Script

local frame = script.Parent
local remote = game.ReplicatedStorage.RemoteEvent

frame.TextButton2.Activated:Connect(function()
    frame.Visible = false
    for i = 3, 0, -1 do
        ChangeText("Start constantly running "..i, "Msgs")
        wait(1)
    end
    remote:FireServer()
    frame.Visible = true
end)

Server Script

local remote = game.ReplicatedStorage.RemoteEvent

remote.OnServerEvent:Connect(function(player)
    for _, v in pairs(game.Players:GetPlayers()) do
        local character = workspace:FindFirstChild(v.Name)
        if character.Humanoid.WalkSpeed > 16 and v.Settings.Playing.Value == true then
            v.Settings.Ran.Value = true
            character.Humanoid.Health = 0
        end
        wait()
    end
end)

You can also simply set the player's health to zero when you change the "Ran" Value instead of needing another if-then clause

If you simply want the individual player to die if their WalkSpeed becomes > 16 then you can use a while loop:

Local Script

local player = game.Players.LocalPlayer
local character = workspace:WaitForChild(player.Name)
local remote = game.ReplicatedStorage.RemoteEvent

while true do
    if player.Character.Humanoid.WalkSpeed > 16 then
        remote:FireServer()
    end
    wait()
end

Server Script

local remote = game.ReplicatedStorage.RemoteEvent

remote.OnServerEvent:Connect(function(player)
    local character = workspace:FindFirstChild(player.Name)
    if character.Humanoid.WalkSpeed > 16 and player.Settings.Playing.Value == true then
        player.Settings.Ran.Value = true
        character.Humanoid.Health = 0
    end
end)

Both examples have a RemoteEvent in ReplicatedStorage named "RemoteEvent" to make sure that the changes to the player happen on the server (where everyone can see them)

0
Thank you! Jxdenx 45 — 5y
Ad

Answer this question