Invoke or Firing doesn't work

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…

You aren’t returning anything in the remote function, also, can you verify the location of the events? there are certain locations where they will not work.

Fixed!

I just created these coins in a local script so the server dont hat any idea that there is even a coin so its not sending something to the server bc the server didnt know that there was something so i just created these coins in custom folders with the name: player.name…“_coins”

i could get the playername easily and so every player on my server have their own coins and nobody could steal the coins from other people.

Why did i create it this way? basicly i saw it often that other players stole coins from other players and that how i fixed it. now every player have their own coins. Ez.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.