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

How can I make it so a player gets 1 point every second when walking?

Asked by
RPWRD 17
7 years ago

Hello, I have been trying to figure out how to make it give 1 point every second that a player is walking. When I click "play" and walk, it gives too many points. I tried putting "wait(1)" in various locations, but it ends up just delaying the amount of points being given.

01amount = 1
02points = "Steps"
03 
04game.Players.PlayerAdded:connect(function(p)
05    p.CharacterAdded:connect(function(c)
06        c:WaitForChild("Humanoid").Running:connect(function(speed)
07            if speed > 0
08                then p.leaderstats[points].Value = p.leaderstats[points].Value + amount
09            end
10        end)
11    end)
12end)

I also have another script that goes with this one to set up the scoreboard here:

1game.Players.PlayerAdded:connect(function(plr)
2    local stats = Instance.new("BoolValue",plr)
3    stats.Name = "leaderstats"
4 
5    local steps = Instance.new("IntValue",stats)
6    steps.Name = "Steps"
7    steps.Value = 0
8end)
0
Also, I think the problem has to do with c:WaitForChild("Humanoid").Running:connect(function(speed) RPWRD 17 — 7y
0
is the game FE? where are the scripts located and what type of scripts are thye creeperhunter76 554 — 7y
0
Try using a loop and check every second if they are moving. raspyjessie 117 — 7y

3 answers

Log in to vote
0
Answered by
movsb 242 Moderation Voter
7 years ago
Edited 7 years ago

You can use the Humanoid.MoveDirection property to determine if the Humanoid is in motion or not.

Humanoid.MoveDirection is a Vector3 that contains data regarding the direction that the humanoid is moving in. Likewise if the Humanoid is not moving at all, it will be 0, 0, 0, therefore you simply need to check if the Humanoid's MoveDirection is not equal to Vector3.new(0, 0, 0) to determine whether or not you should add a point for the elapsed second.

-Here is a basic setup:

01lcoal amount = 1;
02local points = "Steps";
03local wte = wait;
04local vec3 = Vector3;
05 
06local function CheckForWalk(plr, hum)
07    pcall(function()
08        while wte() do
09            if hum.MoveDirection ~= vec3.new(0, 0, 0) then --if the character is moving
10                while wte(1) do --while the player is moving, increase their step points each second.
11                    if hum.MoveDirection ~= vec3.new(0, 0, 0) then
12                        plr.leaderstats[points].Value = plr.leaderstats[points].Value + amount;
13                    else
14                        break;
15                    end
View all 35 lines...

I hope this helps.

0
I was testing, and I found that if you die, it wont give you points anymore. Do you know why? RPWRD 17 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

I tried it out myself. I noticed the the Running event for Humanoid will fire multiple times even if you just move once, that's the cause of it giving multiple points at once. To fix that, I made a debounce for the script. I also noticed that with your method, speed is a constant and will forever add points once you get into motion once, so I used c.Torso.Velocity.magnitude instead. Here's the final script I got working for myself:

01game.Players.PlayerAdded:connect(function(plr)
02    plr.CharacterAdded:connect(function(char)
03        local running = false
04        char:WaitForChild("Humanoid").Running:connect(function()
05            if running == false then
06                running = true
07                while char.Torso.Velocity.magnitude > 0 do
08                    wait(1)
09                    plr:WaitForChild("leaderstats").points.Value = plr.leaderstats.points.Value + 1
10                    print(char.Torso.Velocity.magnitude)
11                end
12                running = false
13            end
14        end)
15    end)
16end)
0
Okay, thank you! RPWRD 17 — 7y
0
np MadWorlds 84 — 7y
Log in to vote
0
Answered by 7 years ago

You can make a loop where it checks if MoveDirection (A property in Humanoids) is not Vector3.new(0,0,0) (Standing Still) and give the player points based on that

01local plr = game.Players.LocalPlayer
02local char = workspace:WaitForChild(plr.Name)
03local Humanoid = char:WaitForChild("Humanoid")
04while true do
05    if Humanoid.MoveDirection ~= Vector3.new(0,0,0) then
06        print("Walking")
07        plr:WaitForChild("leaderstats").points.Value = plr.leaderstats.points.Value + 1
08    else
09        print("Standing")
10    end
11    wait(1)
12end

Answer this question