Coin doesn't work when player respawns into game?

Hi.

I am trying to make a coin in studio, but every time I die inside of the game, then respawn, the coin stops working?

I want to wonder why this is happening, I fixed some mistakes in the scripts but it looks like those mistakes weren’t the problem on why the coin wouldn’t work when you respawned back into the game.

Help please?

Here is a video that explains everything of what I am talking about:
robloxapp-20221109-1247219.wmv (2.7 MB)

Here is the script for the coin collecting:

local plr = game.Players.LocalPlayer
local coins = plr:WaitForChild('Value')

local chr = plr.Character or plr.CharacterAdded:Wait()
local hum = chr:WaitForChild('Humanoid')
local cooldown = 5

hum.Touched:Connect(function(part)
	if part:IsA('MeshPart') and part.Name == 'Coin' then
		
		part.Name = 'CoinCollected'
		part.Transparency = 1
		game.Workspace["Coin grab"]:Play()
		coins.Value += 1
		wait(cooldown)
		wait(1)
		part.Transparency = 0
		part.Name = 'Coin'
		
		-- Repeat process again after this line --
		
	end
end)

Thank you.

I Wouldnt recommend doing stuff like this with LocalScript because it will only change the value on your client

Server Script inside the Coin

local Coin = script.Parent
local Cooldown = 5

Coin.Touched:Connect(function(Hit)
	if (Coin.Transparency == 0) and (Hit.Parent:FindFirstChild("Humanoid")) then 
		local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
		
		Coin.Transparency = 1
		Coin.Name = "CoinCollected"
		
		game.Workspace["Coin grab"]:Play()
		Player:WaitForChild("Value").Value += 1
		
		task.wait(Cooldown)
		Coin.Transparency = 0
		Coin.Name = "Coin"
	end
end)

I usually stuck with the LocalScript type programming because of me thinking that having a script in a bunch of coins would lag the game, but this will do.

Thank you.

1 Like

You could use CollectionService if you don’t want a script in every coin

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.