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

How do I make it so when the color is green, a point will not be distributed?

I tried to make the part (pointPart) turn green when someone collects it and then make it uncollectable while it's green. Everything in the script works, but when the part is green, it will still add a point to leaderstats when someone touches it, I don't want it to.

local pointPart = script.Parent
-- Colors
local blue = Color3.fromRGB(0, 0, 255)
local green = Color3.fromRGB(0,255,0)

-- Services needed
local Players = game:GetService("Players")
local currentColor = pointPart.Color
local canGet = true

	local function onTouch(otherPart)
	local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
	local player = game.Players:FindFirstChild(otherPart.Parent.Name)
	if humanoid and player and canGet and currentColor == blue then
			canGet = false
			player.leaderstats.Gears.Value = player.leaderstats.Gears.Value + 1
			print("Giving player gear")
			pointPart.Color = green
			wait(3)
			canGet = true
	elseif humanoid and player and canGet and currentColor == green then
		print("Player already recieved gear")
	end
end
	
pointPart.Touched:Connect(onTouch)

Thanks

1 answer

✓ Accepted answer

Move the currentColor variable (line 8) to be WITHIN the Touched event handler. So bring line 8 down to line 12 for example. You were saving its original color, not its current color at the time of touch.

1 comment

0

Thanks!

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