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

My fishes won't remove and it won't give me coins, what do I do?

Asked by 2 years ago

So I am making a fishing simulator game, and when I try to remove items from a player and give them in-game currency, it won't do either.

Here is my code:

local plr = game.Players.LocalPlayer

local plrBackpack = plr.Backpack

local sellPart = script.Parent

sellPart.Touched:Connect(function(hit))

    local money = plr.leaderstats.Coins.Value

    if not hit:IsDescendantOf(plr.Character) then return end

    local allFish = plrBackpack:GetChildren()

    for _, Fish in pairs(allFish) do

        if Fish.Name == 'Faceless fish' then

            allFish:Destroy()

            money = money + 5

        end
    end
end)

1 answer

Log in to vote
0
Answered by
Aeventy 20
2 years ago
Edited 2 years ago

Do

local plr = game.Players.LocalPlayer
local plrBackpack = plr.Backpack
local sellPart = script.Parent

sellPart.Touched:Connect(function(hit))
    local coinsValue = Coins.Value

    if not hit:IsDescendantOf(plr.Character) then return end

    for _, Fish in pairs(plrBackpack:GetChildren()) do
        if Fish.Name == 'Faceless fish' then
            Fish:Destroy()
            coinsValue.Value += 5
        end
    end
end)

By the way, I'm pretty sure this is in a local script.

If you want to change the leaderstats, you would have to use a ServerScript.

Ad

Answer this question