I think more logical way of calling your code should be like this:
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
game.Players:FindFirstChild(tostring(hit.Parent)).PlayerGui:FindFirstChild("Confetti").Visible = true
wait(1.5)
game.Players:FindFirstChild(tostring(hit.Parent)).PlayerGui:FindFirstChild("Confetti").Visible = false
game.Players:FindFirstChild(tostring(hit.Parent)).leaderstats.Coins.Value = game.Players:FindFirstChild(tostring(hit.Parent)).leaderstats.Coins.Value + 10
script.Parent:Destroy()
end
end)
Also for respawning you can use module script to respawn it. This actually looked like an old style code to me. Send me code if you have it and I’ll rescript it no problem. I hope this helps.
Do yourself and everyone else a favour, put the player in a variable to avoid annoying redundancy and use the proper functions to do this.
local Players = game:GetService("Players")
script.Parent.Touched:Connect(function (hit)
local character = hit.Parent
if character:IsA("Model") and character:FindFirstChild("Humanoid") then
local player = Players:GetPlayerFromCharacter(character)
if player then
-- Guis don't have a Visible property? Shouldn't do this from the server either.
player.PlayerGui.Confetti.Visible = true
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 10
wait(1.5)
player.PlayerGui.Confetti.Visible = false
script.Parent:Destroy()
end
end
end)