local Script in StarterPlayer Script:
local rs = game:GetService("RunService")
local rps = game:GetService("ReplicatedStorage")
local coins = workspace.Coins
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local amount = script.Amount
rs.Heartbeat:Connect(function()
local range = player:WaitForChild("Range").Value
for i, coin in pairs(coins:GetChildren()) do
local distance = (char.PrimaryPart.Position - coin.Position).Magnitude
if distance <= range then
amount.Value = coin.Amount.Value
script.Coin:Play()
coin:Destroy()
else
amount.Value = 0
end
end
end)
amount.Changed:Connect(function(val)
if val ~= 0 then
rps.AddCoin:InvokeServer()
end
end)
another script from StarterPlayerScripts
local spawnpart = workspace.CoinSpawnPart
local coins = workspace.Coins
local rs = game:GetService("ReplicatedStorage")
local function newcoin()
local coinchance = math.random(0, 10)
if coinchance == 5 and #coins:GetChildren() < 250 then
local x = spawnpart.Position.X + math.random(-spawnpart.Size.X/2, spawnpart.Size.X/2)
local y = spawnpart.Position.Y
local z = spawnpart.Position.Z + math.random(-spawnpart.Size.Z/2, spawnpart.Size.Z/2)
local coin = rs.SpecialCoin:Clone()
coin.Parent = coins
coin.Position = Vector3.new(x, y, z)
elseif coinchance ~= 5 and #coins:GetChildren() < 250 then
local x = spawnpart.Position.X + math.random(-spawnpart.Size.X/2, spawnpart.Size.X/2)
local y = spawnpart.Position.Y
local z = spawnpart.Position.Z + math.random(-spawnpart.Size.Z/2, spawnpart.Size.Z/2)
local coin = rs.Coin:Clone()
coin.Parent = coins
coin.Position = Vector3.new(x, y, z)
end
end
rs.NewCoin.OnClientEvent:Connect(newcoin)
coins.ChildAdded:Connect(function(coin)
game:GetService("RunService").Heartbeat:Connect(function()
local spinspeed = 0.05
coin.CFrame = coin.CFrame * CFrame.Angles(0, spinspeed, 0)
end)
end)
coins.ChildRemoved:Connect(function(coin)
print(coin.Name)
rs.AddCoin:InvokeServer()
end)
Script from Server Script Service:
local rs = game:GetService("ReplicatedStorage")
while wait(0.25) do
rs.NewCoin:FireAllClients()
end
function rs.AddCoin.OnServerInvoke(player)
print("Fired")
end
rs.AddCoins.OnServerEvent:Connect(function(Player)
print(Player)
end)
So why is this not working? i tried everything now and nothing works…