I am trying to code a block that when a player touches propels the player in a certain direction forward and up,
Below is what I have so far but does not work as propels the player the direction they touch the part, is there a better way to do this and get working?
local cd = false
script.Parent.Touched:Connect(function(hit) --script.Parent is a part, in Workspace
if cd then return end
cd = true
if hit.Parent:FindFirstChild("Humanoid") then
local veloc = Instance.new("LinearVelocity",hit.Parent)
veloc.Attachment0 = hit.Parent.HumanoidRootPart.RootRigAttachment
veloc.VectorVelocity = (hit.Parent:GetPivot().LookVector*5 + hit.Parent:GetPivot().UpVector*5)*5
--LookVector is the direction the player is looking at - when looking straight forward, this is (0,0,-1)
--UpVector is the direction which is defined as up - by default, this is (0,1,0)
veloc.MaxForce = 8000
veloc.RelativeTo = Enum.ActuatorRelativeTo.World
game:GetService("Debris"):AddItem(veloc,2)
end
wait(2)
cd = false
end)
Do you want the player to be propelled forward in the direction of the touched part? Or in the direction the character is facing when they touch the part?
local cd = false
local launchDir = script.Parent.CFrame.LookVector+Vector3.new(0,1,0) -- if the part changes orientation during tbe game move this into the function
script.Parent.Touched:Connect(function(hit)
if cd then return end
cd = true
if hit.Parent:FindFirstChild("Humanoid") then
local veloc = Instance.new("LinearVelocity",hit.Parent)
veloc.Attachment0 = hit.Parent.HumanoidRootPart.RootRigAttachment
veloc.VectorVelocity = launchDir*5
veloc.MaxForce = math.huge
veloc.RelativeTo = Enum.ActuatorRelativeTo.World
game:GetService("Debris"):AddItem(veloc,2)
end
task.wait(2)
cd = false
end)