My script isn't working. I'm trying to make a medieval battle game and i have an intvalue inside the player character called "Horses". I want to make it increase the speed if you have more horses. I've tried putting it in startercharacterscripts, replicatedfirst, and serverscriptservice. Here is the code:
local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local horses = character:WaitForChild("Horses").Value horses.Changed:Connect(function() character:FindFirstChild("Humanoid").Walkspeed = 5 if horses > 0 then character:FindFirstChild("Humanoid").WalkSpeed = character:FindFirstChild("Humanoid").WalkSpeed + horses * 0.35 end end)
The problem is that the Changed event has a property parameter which in your case would be the value of horses. For example if the value of horses was changed to 5 then the parameter would say 5 and you should be using that instead of just saying "horses > 0". You also said "Walkspeed" instead of "WalkSpeed" on line 7. Make sure you are also using a local script if you ever use game.Players.LocalPlayer
local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local horses = character:WaitForChild("Horses").Value horses.Changed:Connect(function(property) character:FindFirstChild("Humanoid").WalkSpeed = 5 if property > 0 then character:FindFirstChild("Humanoid").WalkSpeed = character:FindFirstChild("Humanoid").WalkSpeed + property * 0.35 end end)
On line 3, you are taking the value of "Horses", rather than creating a reference to the object. This means that the function at line 5 will never detect a change in the value. Change line 3 to this:
local horses = character:WaitForChild("Horses")
This will reference the object, allowing it to detect a change.