I want to make something where when a part is touched, it launches the player forward, how can i make this?
Combine a touched event with a linear velocity? Is that what you mean?
Regular script, parented to the part you want to launch ppl forward
local FORWARD_FORCE = 100
local UPWARD_FORCE = 10
local obj:BasePart = script.Parent
obj.Touched:Connect(function(partThatTouched:BasePart)
local plr:Player = game.Players:FindFirstChild(partThatTouched.Parent.Name)
if not plr or plr:FindFirstChild("Debounce") then return end
print('wow')
local deb = Instance.new("IntValue",plr) deb.Name = "Debounce" game.Debris:AddItem(deb,1)
local mass = plr.Character.PrimaryPart.AssemblyMass
local gravity = workspace.Gravity
plr.Character.Humanoid.PlatformStand = true task.wait()
plr.Character.HumanoidRootPart.AssemblyLinearVelocity += plr.Character.HumanoidRootPart.CFrame.LookVector*FORWARD_FORCE + Vector3.new(0,UPWARD_FORCE*mass,0)
task.delay(1, function() plr.Character.Humanoid.PlatformStand = false end)
end)
1 Like
-- Variables //
------------
DELAY = 1 -- Amount of seconds until the player can use the launch-pad again.
VERTICAL_VELOCITY = 100 -- Vertical force on launch.
HORIZONTAL_FORCE_1 = -40 -- Edit this until it works for you.
HORIZONTAL_FORCE_2 = 0 -- Edit this until it works for you.
VELOCITY_DELAY = 0.5 -- Amount of seconds which the force lasts.
------------
local Players = game:GetService("Players")
local Part = script.Parent
local DebounceTable = {}
-- Functions //
local function CreateVelocity(Attachment)
local LinearVelocity = Instance.new("LinearVelocity")
LinearVelocity.VectorVelocity = Vector3.new(HORIZONTAL_FORCE_1, VERTICAL_VELOCITY, HORIZONTAL_FORCE_2)
LinearVelocity.MaxForce = math.huge
LinearVelocity.Attachment0 = Attachment
LinearVelocity.Parent = Attachment.Parent
task.wait(VELOCITY_DELAY)
LinearVelocity:Destroy()
end
local function PartTouched(Limb)
local Player = Players:GetPlayerFromCharacter(Limb.Parent)
if DebounceTable[Player] == true or not Player or Player.Parent ~= Players then return end
DebounceTable[Player] = true
local RootPart = Limb.Parent:FindFirstChild("HumanoidRootPart")
local Attachment = RootPart:FindFirstChild("RootAttachment")
if Attachment then
CreateVelocity(Attachment)
end
task.wait(DELAY)
DebounceTable[Player] = false
end
local function PlayerAdded(Player)
DebounceTable[Player] = false
end
local function PlayerLeft(Player)
DebounceTable[Player] = nil
end
Part.Touched:Connect(PartTouched)
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(PlayerLeft)
Put the script inside any part. Hope you like it!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.