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

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

Asked by 1 year ago

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
            canGet = true
    elseif humanoid and player and canGet and currentColor == green then
        print("Player already recieved gear")



1 answer

Log in to vote
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
1 year ago

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.

Thanks! BunjiBloxxer 51 — 1y

Answer this question