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

Speed onTouched leaderboard possible?

Asked by 9 years ago

Before I start, I want to say that I know this isn't an ask and get service, but I don't know if this is possible in the first place.

Is it possible to detect a players speed, then input it into the leaderboard?

Say

local plr = -- I dunno...

script.Parent.Touched:connect(function(Touched)
    if game.Players:FindFirstChild(Touched.Parent.Name) ~= nil then
        local cash = stats:findFirstChild("Jump Distance")
        cash.Value  = plr.Character.Torso.Velocity.magnitude / 1.45

If this was possible, could someone come up with a script for this? That would be great.

  • Michael
0
The WalkSpeed of a Humanoid...? Discern 1007 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago

To add on to coltn5000's code:

game.Players.PlayerAdded:connect(function(Player)
    local ls = Instance.new("IntValue", Player) -- create the leaderstats
    ls.Name = "leaderstats"
    local Speed = Instance.new("IntValue", ls) -- create (INT) Speed
    Speed.Name = "Speed"
    Player.CharacterAdded:connect(function(Character)
    wait()
        Character:WaitForChild("Torso").Changed:connect(function()
            Speed.Value = Character.Torso.Velocity.X>0 and Character.Torso.Velocity.X or Character.Torso.Velocity.Z ---i'm not sure if this is the best way to get the speed of that character, but that's the way I do it.
        end)
    end)
end)

0
I'll probably be using this code. Thanks! Michael007800 144 — 9y
Ad
Log in to vote
1
Answered by 9 years ago

Yes it is possible to get a players speed then input to the leaderboard

Code:

game.Players.PlayerAdded:connect(function(Player)
    local ls = Instance.new("IntValue", Player) -- create the leaderstats
    ls.Name = "leaderstats"
    local Speed = Instance.new("IntValue", ls) -- create (INT) Speed
    Speed.Name = "Speed"
    Player.CharacterAdded:connect(function(Character)
        Character.Humanoid.Changed:connect(function()
            Speed.Value = Character.Humanoid.WalkSpeed -- Players Walk Speed
        end)
    end)
end)

Answer this question