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

(SOLVED) Coin only visible to the player who spawns it?

Asked by 5 years ago
Edited 5 years ago

In my project, the player touches a part that spawns a coin then the player can collect that coin. I want to make it that the coin only be visible to the player who spawns it.

My code:

--touch a part to make the coin appear

local coin = game.ReplicatedStorage.coin
local clone = coin:Clone()
local platform = workspace.Stage1.platform

script.Parent.Touched:connect(function(hit)

        clone.Parent = workspace.Coins.coins1
        clone.Position = platform.Position + Vector3.new(0,5,0)     

end)

.

--touch the coin to update leaderstat
debounce = true
local coin = script.Parent

function touched(hit)
    if (hit.Parent:FindFirstChild("Humanoid") ~= nil and debounce == true) then
        debounce = false 
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    local coins = player.leaderstats.Coins
    local coinsV = coin.value.Value
    coins.Value = coins.Value + coinsV
    wait(0.1)
    coin.CFrame = coin.CFrame + Vector3.new(0,2,0)
    wait(0.1)
    coin.CFrame = coin.CFrame + Vector3.new(0,2,0)
    wait(0.1)
    coin.CFrame = coin.CFrame + Vector3.new(0,2,0)
    wait(0.1)
    coin.Parent = nil
    end 
end 

script.Parent.Touched:Connect(touched)

I had a crazy idea to put the parent of the spawned coin into the Player, but that didn't work. Then I also put the parent as the Character, but other players can see the coin and collect it, too.

1 answer

Log in to vote
0
Answered by 5 years ago

Answer: Local Parts

Ad

Answer this question