#Help needed with currency script.

15 messages · Page 1 of 1 (latest)

atomic shale
#

make a table of players who collected the object

#

and only collect if the player isnt in the table

small mulch
#

uh, how would i do that?

#

like creating the table?

#

@atomic shale

atomic shale
#

{}

small mulch
#

?

atomic shale
#

please learn some basic lua concepts

small mulch
#

sry, im pre new to lua

#

i can give you the coin script I have rn

atomic shale
#

nah

small mulch
#

Code for collecting the collectibles:

local toolName = "CoinCollector"
local currency = "Coin"

local function collectItem(obj, otherPart)
    local player = game.Players:FindFirstChild(otherPart.Parent.Name)
    if player then
        if player.Character:FindFirstChild(toolName) then
            local amount = obj.Amount.Value
            obj:Destroy()
            player.leaderstats[currency].Value += amount
        end
    end
end

for _, obj in pairs(folder:GetChildren()) do
    if obj:IsA("Model") and obj:FindFirstChild("Hit") then
        obj.Hit.Touched:Connect(function(otherPart)
            collectItem(obj, otherPart)
        end)
    end
end```
small mulch
#

would i add the table in this scritp?

#

like add an if statement before the the collect item function