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

The script works only for one part but not for the another ones?

I'm currently developing a simulator game and I want to make people spam on the blocks. I have a problem and it is that this script works for one block:

local firstPart = game.Workspace.firstPart
local secondPart = game.Workspace.secondPart
local thirdPart = game.Workspace.thirdPart

local oneClick = 10

game.Players.PlayerAdded:Connect(function(plr)
	local LS = Instance.new("Folder", plr)
	LS.Name = "leaderstats"
	
	local test = Instance.new("IntValue", LS)
	test.Name = "Test"
	
	firstPart.ClickDetector.MouseClick:Connect(function()
		test.Value = test.Value + oneClick
	end)
	
	if test.Value >= 100 then
		secondPart.ClickDetector.MouseClick:Connect(function()
			test.Value = test.Value + oneClick * 5
		end)
	end
	
	if test.Value >= 500 then
		thirdPart.ClickDetector.MouseClick:Connect(function()
			test.Value = test.Value + oneClick * 25
		end)
	end
end)

I don't know what to do, it doesn't say there's any error but it doesn't work for the second part and the third one. And yes, I have tried several things but they did not work either.

3 comments

0

The problem is specifically is that the script works for one block and not the 2 others, there also are no errors in the console.

0

Have you added 100+ value to Test before clicking on the second block, and the same but with 500 on the third block? Because I don't really see something wrong here.

0

Yes even when the Test's value has 100+ points, the second block doesn't work. It goes to the third as well.

1 answer

I think that it is because it only connects once the player joins AND test.Value is greater or equal than 100 or 500. When the requirement is met the event is not connected because the player already joined and the event PlayerAdded was already fired. Try to move the check for test.Value inside of the function that is being connected to the event.

1 comment

0

Ok, I will try.

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