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

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

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

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.

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