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.
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)