Problem with touch event when player lags

Hello, so, the problem that im having rn is kinda interesting, im making a game were a part is moving via tweening, the idea is that when the player gets touched by it, “dies”, i use a server side script that just uses the Part.Touched:Connect(function() for detecting when a players touches the part.
the problem is, whenever a player lags and the part touches him, the touch event doesnt fire, ill show a video for more understanding:

here’s the link (couldn’t upload here bc its too big)

its pretty weird bc as i know the lag of the player shouldn’t affect the server-side scripts, but yeah here i am making this post.

someone knows how to solve this? thanks :slight_smile:

6 Likes

Well you could try using a local script to kill the player instead of server script

4 Likes

it doesnt really kills the player, it just teleports him to the spawn and it plays a cinematic. but yeah ig ill try using a local script to see if it works

3 Likes

Snice you are dealing with moving parts try to make zone kill like if the monster get closer to player 2,3 studs kill him, You can do this with region3 welded to monster or checking distances btween the monster and the player.

Serverside lag real time…
Video link

function Get_Distance(Charactor1, Charactor2) -- return distance btween two chars
    if not Charactor1 and not Charactor2 and not Charactor1:FindFirstChild("HumanoidRootPart") and not Charactor2:FindFirstChild("HumanoidRootPart")  then return end
    return (Charactor1.HumanoidRootPart.Position - Charactor2.HumanoidRootPart.Position).Magnitude
end

print(Get_Distance(Monster, player.Character)) -- prints distances. 
3 Likes

yeah i tried and i got the same problem :confused:

2 Likes

it sounds like a good plan, ill try it later, ty for replying :smiley:

2 Likes

okay, so i ended up doing the region3 thing (kinda because i used overlapParams since they are the same) to detect the player whenever a part of him is in the hitbox of the monster

(the script that i made with the overlapParams)

rs.Stepped:Connect(function()
	local parts = workspace:GetPartsInPart(hitbox,overlapParams)
	for i,part in pairs(parts) do
		if part.Parent:IsA("Model") and part.Parent:FindFirstChild("Humanoid") and not debounce then
			print("touched")
			debounce = true
			spawn(function()
				task.wait(1)
				debounce = false
			end)
		end
	end
end)

the thing is that for some reason im still getting the same problem, when the player lags, it doesnt detect it :confused:
(also i dont really want to use the distance method because the monster has a big part for his hitbox, so the position of the hitbox would be kinda innacurate)

2 Likes

Where are you doing the script at?

Edit: Nvm

2 Likes

You can use attachment for distance method as well…

Plugin Test - Roblox Studio 2023-06-20 10-04-55

local RS = game:GetService("RunService")

local Char = game:GetService("Players").LocalPlayer.Character or game:GetService("Players").LocalPlayer.CharacterAdded:Wait()

local Attachment = game.Workspace.Part.Attachment

function Get_Distance(Charactor1, Attachment) -- return distance btween two chars
	if not Charactor1 and not Attachment and not Charactor1:FindFirstChild("HumanoidRootPart") then return end
	return (Charactor1.HumanoidRootPart.Position - Attachment.WorldCFrame.Position).Magnitude
end

RS.Stepped:Connect(function()
	print(Get_Distance(Char,Attachment))
end)
2 Likes

ok so i kinda feel stupid but the reason the touched script wasn’t working is because i was testing this on studio, i guess studio considers server-side scripts as local…

tysm @KSA_Developer for the help really appreciate it :slight_smile:

Solution: the lag just affects the script in roblox studio, in the platform it doesnt really matter.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.