Hi, since I'm making a TTT game I need to make a function that hide a player corpse in a barrel, already done that. This function is triggered if the player press E (ok) and if the player distance radius from the corpse is 2-3 but I don't know how!. This is the code in a LocalScript, which his Parent contains a ClickDetector to get the corpse, easy:
local player= game.Players.LocalPlayer local mouse = player:GetMouse() local pInfo = script.Parent.PlayerInfo.Wrapper local target = script.Parent-- The corpse local hid = false function func_1637702a() -- hide the corpse (transparency => 0) and spawn barrel end function keyPress(par1) if par1 == "e" and hid == false then local td = player:FindFirstChild("TempData") local tp = td:FindFirstChild("Type") --if player radius position <= corpse radius position by 2 then if type.Value == "Traitor" then if pInfo.HealthStatus.Text == "Corpse" then func_1637702a() hid = true else print("The traitor tried to hide an alive player") end else print("A player tried to hide a corpse while not being a traitor") end --end end end mouse.KeyDown:connect(keyPress)
Thanks for helping me!
Here you go:
local player= game.Players.LocalPlayer local mouse = player:GetMouse() local pInfo = script.Parent.PlayerInfo.Wrapper local target = script.Parent-- The corpse local hid = false function func_1637702a() -- hide the corpse (transparency => 0) and spawn barrel end function keyPress(par1) if par1 == "e" and hid == false then local td = player:FindFirstChild("TempData") local tp = td:FindFirstChild("Type") if (player.Character.Torso.Position-target.Torso.Position).magnitude <= 2 then if type.Value == "Traitor" then if pInfo.HealthStatus.Text == "Corpse" then func_1637702a() hid = true else print("The traitor tried to hide an alive player") end else print("A player tried to hide a corpse while not being a traitor") end end end end mouse.KeyDown:connect(keyPress)
I might have located objects wrongly, but that should be easy to fix.
Edit:
I guess I could tell something about what I did. So to find out distance between two positions, you can use roblox's vector3 utility function magnitude
. Essentially, it returns the lenght of vector. Since we have 2 positions, we can get the vector in between by subtracting one vector from other. Now the lenght of that vector equals distance.