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:
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
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.
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.
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
(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)
You can use attachment for distance method as well…
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)
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…