Script not working (please help!)

this script is supposed to change the player’s walkspeed to the value of speed, but it just keeps setting it to whatever the initial value is. I’ve tried asking chat GPT, and i couldnt find anything anywhere.

my script:

local RunService = game:GetService("RunService")

local speed = game.StarterPlayer.StarterCharacterScripts.SpeedSetter.Speed

local function updateWalkspeed()
	for _, player in pairs(Players:GetPlayers()) do
		local character = player.Character
		if character then
			local humanoid = character:FindFirstChildOfClass("Humanoid")
			if humanoid then
				humanoid.WalkSpeed = speed.Value
			end
		end
	end
end

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		updateWalkspeed()
	end)
end)

Players.PlayerRemoving:Connect(function(player)
end)

RunService.Heartbeat:Connect(function()
	updateWalkspeed()
end)

speed.Changed:Connect(function()
	updateWalkspeed()
end)
1 Like

Players.PlayerAdded:Connect(function(player) gives you the player so you don’t really need the updateWalkspeed() function

simply change this

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		updateWalkspeed()
	end)
end)

into this

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Wait().Humanoid.WalkSpeed = speed.Value
end)

Also Players doesn’t seem to be defined, and I would remove the Runservice.Heartbeat and other functions as it would slow performance

Is speed a propriety or a Value?

it is an IntValue
(at least 30 limit)

the script is working the same as it did before

Just realized something, did you mean to change the speed of the player as the speed.Value changes? I’d like more clarification on what your goal is

the goal is to make it so whenever the speed.value changes, the player’s walkspeed is changed to match the newspeed.value

Add this somewhere

speed.Changed:Connect(function()
	for _,plr in game.Players:GetChildren() do
		plr.Character.Humanoid.WalkSpeed = speed.Value
	end
end)

it still does the same thing, it just sets the speed.value to whatever it starts as

Is this a local script or a server script? Also how are you changing the speed.Value

local script, inside of startercharacterscripts

Change it into a regular Script and put it into ServerScriptService

Im currently getting the attempt to index nil with ‘Humanoid’ error on line 13

local RunService = game:GetService("RunService")

local speed = script.Speed

speed.Changed:Connect(function()
	for _,plr in game.Players:GetChildren() do
		plr.Character.Humanoid.WalkSpeed = speed.Value
	end
end)

game.Players.PlayerAdded:Connect(function(player)
	player.Character.Humanoid.WalkSpeed = speed.Value
end)

change this

player.Character.Humanoid.WalkSpeed = speed.Value

into this

player.CharacterAdded:Wait().Humanoid.WalkSpeed = speed.Value
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.