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)

4 comments
Just a note for those wondering. Yes, i'm very novice.
So where is the last code sample located? Tip: remember to always put your code in brackets so its easier to read
Last code sample? As in the normal script. ServerScriptServices.
My theory is that when the "money" part gets deleted the local script loses track of the part since it got deleted. You should just put a script in the part that tracks when it gets touched, that way when the part respawns the script is already parented to the part.