What Script Is It In Well Sometimes LocalScripts are the problem for everything But this time No Lol.
The Code
local Coin = script.Parent
Coin.Touched:Connect(function(Hit)
local Humanoid = Hit.Parent:FindFirstChildWhichIsA('Humanoid')
if Humanoid then
game.Players.LocalPlayer.leaderstats.Value = game.Players.LocalPlayer.leaderstats.Value+1
Coin.Transparency = 1
wait(60)
Coin.Transparency = 0
end
end)
local Coin = script.Parent
local d = false
Coin.Touched:Connect(function(Hit)
if d then return end
d = true
local Humanoid = Hit.Parent:FindFirstChildWhichIsA('Humanoid')
if Humanoid then
game.Players.LocalPlayer.leaderstats.Value += 1
Coin.Transparency = 1
wait(60)
Coin.Transparency = 0
end
d = false
end)
It uses a scripting concept called “debounce” to make sure the .Touched event’s function isn’t being used more than once at a time.
local Coin = script.Parent
local d = false
Coin.Touched:Connect(function(Hit)
if d then return end
d = true
local Humanoid = Hit.Parent:FindFirstChildWhichIsA('Humanoid')
if Humanoid then
game.Players.LocalPlayer.leaderstats.Coins.Value += 1
Coin.Transparency = 1
wait(60)
Coin.Transparency = 0
end
d = false
end)
Another issue might be the fact that this code is client sided, your best bet is to turn the code into serversided code, this is how you’d do so:
local Coin = script.Parent
local d = false
Coin.Touched:Connect(function(Hit)
if d then return end
d = true
local Humanoid = Hit.Parent:FindFirstChildWhichIsA('Humanoid')
if Humanoid then
local Plr = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Plr then
Plr.leaderstats.Coins.Value += 1
Coin.Transparency = 1
wait(60)
Coin.Transparency = 0
end
end
d = false
end)
You’ll need to add a debounce so the player doesn’t keep getting coins even if it’s invisible.
Your trying to increase a folder’s value, folder’s don’t have a value so the player’s coins wont be increased and would error.
local Coin = script.Parent
local Touched = false
Coin.Touched:Connect(function(Hit)
if Touched then
return
end
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Player then
Touched = true
Player.leaderstats.Coins.Value += 1
Coin.Transparency = 1
wait(60)
Coin.Transparency = 0
Touched = false
end
end)
If it’s a LocalScript this wouldn’t work since then the coin change would only replicate to the player’s screen and LocalScripts only work in places which are a descendant of a Player.