Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

WalkSpeed value isn't changing?

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.

1 comment

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?

1 answer

✓ Accepted answer

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)

1 comment

0

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.