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

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

Asked by 4 years ago

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

Log in to vote
1
Answered by 4 years ago
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)
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? Wowboylol 4 — 4y
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 Gameplayer365247v2 1055 — 4y
0
thanks! Wowboylol 4 — 4y
Ad

Answer this question