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

I need help on this script, It was working properly and I changed nothing, now it doesn't work?

Asked by 6 years ago

So I was working on a script and I got it to work. It's a script that gives the player +10 Stumble Points upon touching the parent (a brick). It was working, I changed nothing with the script and now it doesn't work correctly. It still gives points, but instead of on touching the brick, it just gives the points on a loop. Any help is great! Heres the script:

game.Players.PlayerAdded:connect(function(plr)
    local folder = Instance.new("Folder", plr)
    folder.Name = "leaderstats"
    local gems = Instance.new("IntValue", folder)
    gems.Name = "Gems"
    local StumblePoints = Instance.new("IntValue", folder)
    StumblePoints.Name = "StumblePoints"
end)


while wait(5) do
    for _,player in pairs(game.Players:GetPlayers()) do
        if player:FindFirstChild("leaderstats") then
            player.leaderstats.StumblePoints.Value = player.leaderstats.StumblePoints.Value + 10
        end
    end
end

Nothing was changed in the Output spot when i worked on other things. Nothing is said about the script in there too.

0
use a touched event theking48989987 2147 — 6y
0
Ok, will do. superawesome113 112 — 6y
0
Do you have it in a script? If so you might want to change it to a local script Potaaden -18 — 6y

1 answer

Log in to vote
0
Answered by
zor_os 70
6 years ago
Edited 6 years ago

You only used a loop finding all players who had leaderstat when you should have used a touch event for the player who runs into the brick

game.Players.PlayerAdded:connect(function(plr)
    local folder = Instance.new("Folder", plr)
    folder.Name = "leaderstats"
    local gems = Instance.new("IntValue", folder)
    gems.Name = "Gems"
    local StumblePoints = Instance.new("IntValue", folder)
    StumblePoints.Name = "StumblePoints"
end)     

local debounce = false
script.Parent.Touched:connect(function(hit) -- when player hits brick
    if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
        debounce = true
        local player = game.Players:FindFirstChild(hit.Parent.Name)
        if player:FindFirstChild("leaderstats") then
            player.leaderstats.StumblePoints.Value = player.leaderstats.StumblePoints.Value + 10
        end
        wait(5)
        debounce = false
    end
end)
0
Oh ok, Thank you so much. Sorry I didn't reply faster, I was eating dinner. superawesome113 112 — 6y
1
So I plugged in the script and it gave thousands of Stumble Points because there is no delay, could I also get a little help with that? I tried doing "while wait(5) do" with your code inside of it, but that doesn't seem to work. superawesome113 112 — 6y
0
ok I updated the script so it should only activate every 5 seconds zor_os 70 — 6y
0
Works perfectly! Thank you so much, that script was the ONE thing that was holding me back from finishing the rest of my game. If you want to see the progress: https://www.roblox.com/games/2496018369/Stumble-Sim-Test-Server superawesome113 112 — 6y
0
I know the feeling, glad I could help :) zor_os 70 — 6y
Ad

Answer this question