The script below will respawn the player and reward them 10 points, but if multiple people hit it at once, it only does it to one person and no one else. Any help?
local respawnInProgress = false local respawnTime = 0.1 local pointsReward = 10 script.Parent.Touched:Connect(function(hit) local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) if player and not respawnInProgress then respawnInProgress = true player.leaderstats.Points.Value = player.leaderstats.Points.Value + pointsReward player:LoadCharacter() wait(respawnTime) respawnInProgress = false end end)
Try using a local script to check if the local player was the one the spawner touched you where using a server script improperly
use a local script for this one. try putting it into starter character scripts
local respawnInProgress = false local respawnTime = 0.1 local ReplicatedStorage = game:GetService("ReplicatedStorage") local TouchedEvent = ReplicatedStorage:WaitForChild("TouchedEvent") local player = Players.LocalPlayer game.workspace.your-object-name-here.Touched:Connect(function(hit) if player and not respawnInProgress then respawnInProgress = true TouchedEvent:FireServer() player:LoadCharacter() wait(respawnTime) respawnInProgress = false end end)
local pointsReward = 10 local ReplicatedStorage = game:GetService("ReplicatedStorage") local TouchedEvent = Instance.new("RemoteEvent", ReplicatedStorage) TouchedEvent.Name = "TouchedEvent" function TouchedFired(player) -- this gets automatically submitted by the client player.leaderstats.Points.Value = player.leaderstats.Points.Value + pointsReward end TouchedEvent.OnServerEvent:Connect(TouchedFired)
This Should Solve your problem about only one player getting the reward