So, I have a leaderstat called "Speed" and I want the player's character's speed to be equal to the players leaderstat plus the original (16) \ EX: Leaderstats Speed = 23 then character speed = 39 Here's what I have, it definently does not work (Localscript in StarterCharacterScripts):
local plr = game.Players.LocalPlayer plr.leaderstats.Speed.Changed(function() wait(0.05) local char = plr.Character local Lname = char.Name local h = char.Humanoid local tt = h.WalkSpeed - h.WalkSpeed local gg = plr.leaderstats.Speed while true do h.WalkSpeed = tt + gg end end)
If it dont work PM on Roblox
First of all you have called the event wrong. To call an event you do this:
script.Parent.Touched:Connect(function() end)
.Touched
is the event, and :Connect
connects the event to the function.
Secondly, you are calling an event that will most likely never happen. You are trying to change the players speed in the event speed.Changed
.
Also, in a while true do
loop, you MUST have a wait()
otherwise the game will just crash.
local player = game:GetService("Players").LocalPlayer --gets player local char = player.Character or player.CharacterAdded:Wait()--gets character local humanoid = char:FindFirstChild("Humanoid")--gets the humanoid local leaderstats = player:FindFirstChild("leaderstats") --gets leaderstats local speed= leaderstats:FindFirstChild("Speed") --gets the speed humanoid.WalkSpeed = humanoid.WalkSpeed + speed.Value --this will get the humanoid, then the humanoids speed, and add speeds value to it --make sure 'speed' actually has a value
Defining variables.
local player = game:GetService("Players").LocalPlayer local char = player.Character
Waits for the players Speed value in leaderstats to change.
player.leaderstats.Speed.Changed(function()
Once it is changed, it will set their WalkSpeed to whatever their Speed leaderstat value is equal to, plus an additional 16.
char.Humanoid.WalkSpeed = player.leaderstats.Speed.Value + 16 end)
Full Code;
local player = game:GetService("Players").LocalPlayer local char = player.Character player.leaderstats.Speed.Changed(function() char.Humanoid.WalkSpeed = player.leaderstats.Speed.Value + 16 end)
Hope I helped! Happy developing!
Basically it is detecting a change. If it hasn't changed then nothing happens So set it to it before it happens
local player = game.Players.LocalPlayer local char = player.Character char.Humanoid.WalkSpeed = player.leaderstats.Speed.Value player.leaderstats.Speed.Changed(function() char.Humanoid.WalkSpeed = player.leaderstats.Speed.Value end)