game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Value = 0
coins.Parent = leaderstats
end)
local coinParts = game.Workspace.Coins
local active = true
coinParts.Coins1.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid and active then
local plr = game.Players:GetPlayerFromCharacter(hit.parent)
plr.leaderstats.Coins.Value += math.random(1,5)
coinParts.Coins1.Transparency = 0.5
active = false
task.wait(5)
active = true
end
end)
local coinParts = game.Workspace.Coins
local active = true
coinParts.Coins2.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid and active then
local plr = game.Players:GetPlayerFromCharacter(hit.parent)
plr.leaderstats.Coins.Value += math.random(1,5)
coinParts.Coins2.Transparency = 0.5
active = false
task.wait(5)
active = true
end
end)
local coinParts = game.Workspace.Coins
local active = true
coinParts.Coins3.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid and active then
local plr = game.Players:GetPlayerFromCharacter(hit.parent)
plr.leaderstats.Coins.Value += math.random(1,5)
coinParts.Coins3.Transparency = 0.5
active = false
task.wait(5)
active = true
end
end)
#What would have been a better way to format this script?
5 messages · Page 1 of 1 (latest)
** You are now Level 2! **
use loops basicly
for _,coin in ipairs(theFolderCoinsAreIn:GetChildren()) do
coin.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid and active then
local plr = game.Players:GetPlayerFromCharacter(hit.parent)
plr.leaderstats.Coins.Value += math.random(1,5)
coinParts.Coins3.Transparency = 0.5
active = false
task.wait(5)
active = true
end
end)
end
this may be enough for you ig
sorry for bad format or maybe some spelling errors bcz i wrote that on discord