What I want is to check velocities of parts flying through the air
This way I can
-Make them do nothing to the player if it’s too slow
-Make them stick into the player if they’re going fast enough
-Make them instantly kill the player if they’re going really fast
How would I go about doing this?
I have my current code written here as a base but it doesn’t really work so
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
character:WaitForChild("Humanoid").Touched:Connect(function(touchedPart, bodyPart)
local vel = touchedPart.AssemblyLinearVelocity
if vel.X > 50 or vel.Y > 50 or vel.Z > 50 or vel.X < -50 or vel.Y < -50 or vel.Z < -50 then
game.ReplicatedStorage.remote:FireServer(touchedPart)
end
end)
Vectors have a property called Magnitude which represents the length of the vector. It’s basically a scalar. You can use it to detect the speed of an object.
heres the new code, anything seem wrong with it before i test it?
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
character:WaitForChild("Humanoid").Touched:Connect(function(touchedPart, bodyPart)
local vel = touchedPart.AssemblyLinearVelocity
if math.abs(vel.Magnitude) > 5 then
game.ReplicatedStorage.remote:FireServer(touchedPart)
end
end)
(the remote event is just saying to kill the player and delete the part on the server, i dont think i need to do the player kill part on the server but whatever)