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

Make character speed equal to leaderstat?

Asked by 7 years ago
Edited 7 years ago

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)
0
You are checking an infinite times a second. When will that second pass? hiimgoodpack 2009 — 7y
0
You realise your 'tt' variable is going to be equal to 0 right? awfulszn 394 — 7y
0
i think originally i wanted player walkspeed to be equal to just their speed, not their speed plus their leaderstat taunter165 30 — 7y
0
hiimgoodpack, so how would i fix that taunter165 30 — 7y

3 answers

Log in to vote
-1
Answered by
iddash 45
7 years ago
Edited 7 years ago

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

0
What are you doing? Dissembling your computer and touching the bytes that make up the value object? hiimgoodpack 2009 — 7y
0
doesnt work taunter165 30 — 7y
0
did u put this LocalScript in PlayerCharacterScripts? iddash 45 — 7y
Ad
Log in to vote
0
Answered by
awfulszn 394 Moderation Voter
7 years ago
Edited 7 years ago

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!

0
Ive tampered and moved from local to reg script but no matter what it still shows the same error taunter165 30 — 7y
0
"leaderstats is not a valid member of Player" taunter165 30 — 7y
0
If you've changed it to a server script, you can't get the local player from it, only in studio. And you are not waiting for leaderstats to appear. Add a variable at the top of your script that has :WaitForChild("leaderstats") awfulszn 394 — 7y
0
doesnt work taunter165 30 — 7y
0
Errors? awfulszn 394 — 7y
Log in to vote
0
Answered by 6 years ago

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)

Answer this question