Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Player respawner glitching when multiple people hit it at once?

Asked by
R_alatch 394 Moderation Voter
4 years ago

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

Log in to vote
0
Answered by 4 years ago

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

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 HappyTimIsHim 652 — 4y
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 HappyTimIsHim 652 — 4y
0
also this won't fix the fact that they dont get respawned either R_alatch 394 — 4y
0
Then you try to make an answer if you know what you are doing better marine5575 359 — 4y
Ad

Answer this question