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

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

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

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