The idea here is i step on a part, its fires a remote event that will destroy the part and add a point to the players score. However when i test it in a server and studio, i step on the part once and it works, the part respawns and i step on it again, and nothing happens
Code local script, stored in StarterPlayerScripts: local RS = game:GetService("ReplicatedStorage")
wait(5) local money = workspace.moneyPart:FindFirstChildWhichIsA("Part")
local function onTouch() print("Working 1") game.ReplicatedStorage.RemoteEvent:FireServer() end
money.Touched:Connect(onTouch)
Code normal script, stored in ServerScriptService: game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player) print("working") local money = workspace.moneyPart:FindFirstChildWhichIsA("Part")
local function onTouch(otherPart) local humanoid = otherPart.Parent:FindFirstChild("Humanoid") if humanoid then local player = game.Players:FindFirstChild(otherPart.Parent.Name) money:Destroy() if player then player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1 end end end money.Touched:Connect(onTouch)
end)
From looking at this, it looks like you could make it completely server sided. One thing you shouldn't do is have a connection inside of a remote event unless you plan on disconnecting it.
The reason why it doesnt fire again is because you're not checking for when the part updates.
I would make it like this, all inside of your server script. (assuming theres only one part at a time)
local MoneyHolder = workspace:WaitForChild("moneyPart") local Connection function onTouch(otherPart) local humanoid = otherPart.Parent:FindFirstChild("Humanoid") if humanoid then local player = game.Players:FindFirstChild(otherPart.Parent.Name) money:Destroy() if player then player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1 end end if Connection then Connection:Disconnect() end end local StartingMoney = MoneyHolder:FindFirstChildWhichIsA("Part") if StartingMoney then Connection = StartingMoney.Touched:Connect(onTouch) end MoneyHolder.ChildAdded:Connect(function(object) if object:IsA"Part" then Connection = object.Touched:Connect(onTouch) end end)