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

How would I make a coin that multiple players can collect?

Here's the script

local Value = 10
local Enabled = true

script.Parent.Touched:Connect(function(hit)
	if Enabled then
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if Player then
			local lstats = Player:WaitForChild("leaderstats")
			lstats.Gold.Value = lstats.Gold.Value + Value
			Enabled = false
			script.Parent.Transparency = 1
			if script.Parent:FindFirstChild("Sound") then
				script.Parent:FindFirstChild("Sound"):Play()
			end
		end
	end
end)

Right now, when a player collects the coin it disappears, but no other players can collect the coin. How would I make it so the coin only disappears on the player's screen (the player who touched the coin), but not on anyone else's?

1 answer

✓ Accepted answer
local Value = 10
local Enabled = true

script.Parent.Touched:Connect(function(hit)
    if Enabled then
        local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if Player then
            local lstats = Player:WaitForChild("leaderstats")
            lstats.Gold.Value = lstats.Gold.Value + Value
            Enabled = false
            script.Parent.Transparency = 1
            if script.Parent:FindFirstChild("Sound") then
                script.Parent:FindFirstChild("Sound"):Play()
            end
          game.ReplicatedStorage.destroycoin:FireClient(Player,script.Parent)--send to the player it picked up the coin
        end
    end
end)

local script here

game.ReplicatedStorage.destroycoin.OnClientEvent:Connect(function(coin)
coin:Destroy()--destroys the coin on the client side only
end)

3 comments

0

Sorry, I've just started programming. In the output I got "FireClient is not a valid member of LocalScript". Wasn't sure what to with the local script, am I suppose to place the local script in the coin object or in replicated storage?

0

you are ment to put in a remote event in replicatedstorage called destroycoin and put in a local script in backpack or startergui,also the bigger script should be a server script if it isnt already

0

thanks!

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