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

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

Log in to vote
0
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.

0
Thanks! BunjiBloxxer 51 — 1y
Ad

Answer this question