Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

3 comments

0

use a touched event

0

Ok, will do.

0

Do you have it in a script? If so you might want to change it to a local script

1 answer

✓ Accepted answer

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)

5 comments

0

Oh ok, Thank you so much. Sorry I didn't reply faster, I was eating dinner.

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.

0

ok I updated the script so it should only activate every 5 seconds

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

0

I know the feeling, glad I could help :)

This discussion is preserved as it was. New answers, comments, and votes are closed.