Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Player respawner glitching when multiple people hit it at once?

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)

1 answer

Try using a local script to check if the local player was the one the spawner touched you where using a server script improperly #Client 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)

Server

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

4 comments

0

first of all thats not a really good way at doing it because an exploiter can easily fire that remote and get unlimited cash

0

you should also send the character and check the magnitude of the character and the part to make sure he's not spamming it

0

also this won't fix the fact that they dont get respawned either

0

Then you try to make an answer if you know what you are doing better

This discussion is preserved as it was. New answers, comments, and votes are closed.