Can't find issue with .Touched kill bricks

i have been working on a game recently, and i got into a bug that i can’t understand what is causing

basically, in the game, after you touch a person, they die, normally it works, but today after i called a friend in to check it, when he touches me, i don’t die, but when i touch him, he does die, i didn’t touch the script and this is the first time i’ve seen this bug

here is the script

local Func = Plr.Touched:Connect(function(target)
					wait(0.2)
					if game.Workspace.Players2:FindFirstChild(target.Name) and game.ReplicatedStorage.Context.Continue.Value == false and game.ServerScriptService.PlayerStats[Plr.Name].Ping.Value < 400 then
						target:Destroy()
						announceModule.announce(Players:GetPlayerByUserId(target.Name).Name.." Just Got Eaten!")
						game.ReplicatedStorage.Context.Continue.Value = true
					end
				end)

and here is the game this is being caused in
nothing comes up in the console, the script continues normally and doesn’t break, i can’t seem to find what does this

1 Like

I’m a bit confused. Couldn’t you just use the target parameter instead of checking if there’s a child of workspace.Players2 that’s named the same as target?

1 Like

By this, do you mean that it passes through the if statement or just gives no errors? Assuming it’s the latter, add a print message inside your if statement and see if it comes up in the console.

what i mean is that it gives no errors, but the problem is, i don’t know when this happens so most of the time it works normally, so even after adding the print message i just have to make this bug happen, i will still do it tho.

well, it works the same way so i don’t see a problem with that

nvm i just found out am the only one that always goes trough this so getting prints was easy
here is the print
image
here is what i told the script to print

print(target.Name)
print(game.ReplicatedStorage.Context.Continue.Value)
print(game.ServerScriptService.PlayerStats[hungryPlr.Name].Ping.Value)
for i, v in pairs(game.Workspace.Players2:GetChildren()) do
	print(v.Name.." is a child of Players2")
end

after looking at this i can see that the problem is from the ping, i will try to check on the script and fix what i see then come back to you if i solve the problem or fail to

nope, cant find the problem, the ping script looks fine to me

Client

local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage:WaitForChild("PingCheck")

local function ping()
	local send = tick()
	remoteEvent:FireServer(send)
end

while true do
	ping()
	wait(3)
end

Server

local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage:WaitForChild("PingCheck")

remoteEvent.OnServerEvent:Connect(function(player, send)
	local pingVal = game.ServerScriptService.PlayerStats[player.UserId].Ping
	pingVal.Value = tick() - send
	print(pingVal.Value)
end)

i don’t understand why am getting such high numbers

number tick()
Returns how much time has elapsed, in seconds, since the UNIX epoch, on the current local session’s computer.
The UNIX epoch is represented by the date January 1st, 1970.

from Roblox Globals
Because the value from tick() is not synchronized, you can’t use it to measure ping.
Additionally, you shouldn’t need to measure ping anyway. Roblox handles retrying network events for you.

i measure ping because when a person has high ping and touches someone else they get destroyed without seeing the person with high ping move, which is unfair, additionally, for the person with high ping, everyone will be frozen, but he can still touch them and destroy them even tho he technically didn’t touch them

If you want to prevent this, you should verify events on the server. A client can spoof .Touched() events, a client can fire your remote to kill, etc.
Whenever you recieve a request to kill somebody, you should check if they’re close enough to do that on the server.

1 Like

hmm i see, for some reason i didn’t think about that, however, just for the future I’d like to know what causes my main problem

I am assuming:

  • plr is a BasePart in workspace.Players2
  • BaseParts in workspace.Players2 are named after user ids
local Func = Plr.Touched:Connect(function(target)
    if game.Workspace.Players2:FindFirstChild(target.Name) and game.ReplicatedStorage.Context.Continue.Value == false then
        game.ReplicatedStorage.KillPlayer:FireServer(target.Name)
        announceModule.announce(Players:GetPlayerByUserId(target.Name).Name.." Just Got Eaten!")
        game.ReplicatedStorage.Context.Continue.Value = true
    end
end)

Now, in a Script (probably in ServerScriptService):

game.ReplicatedStorage.KillPlayer.OnClientEvent:connect(function(player: Player, kill: number)
    local block = game.Workspace.Players2:FindFirstChild(kill)
    local pblock = game.Workspace.Players2:FindFirstChild(player.UserId)
    -- Make it so you must be within 10 studs of someone to kill them. Lower if needed.
    if (block and pblock) and ((block.Position - pblock.Position) > 10) then
        block:Destroy()
    end
end)

This assumes that game.ReplicatedStorage.KillPlayer is a RemoteEvent.

the first script is already a server script lol, don’t worry, i will work on the script by myself, but thank you, that was very helpful !

1 Like

You are using unix time, which is in seconds. In the original script, you are checking if they have a ping of over 400 seconds.

yes but, why does it print 14k ? shouldn’t it print 0 or something ?