local RPS = game:GetService("ReplicatedStorage")
local coinTemplate = RPS.Coin
local player = game:GetService("Players").LocalPlayer
local function spawnCoin()
local char = player.Character
local root = char:FindFirstChild("HumanoidRootPart")
if not root then return end
local Coin = coinTemplate:Clone()
Coin.Parent = game.Workspace
Coin.Position = root.Position + Vector3.new(math.random(-10,10), 5, math.random(-10,10))
Coin.Anchored = false
Coin.Touched:Connect(function(hit)
if hit:IsDescendantOf(char) then
local stats = player:FindFirstChild("leaderstats")
if stats and stats:FindFirstChild("Coin") then
stats.Coin.Value += 1
Coin:Destroy()
end
end
end)
end
task.spawn(function()
while true do
task.wait(5)
print("Called")
spawnCoin()
end
end)