I want the player to shoot up when touching a part, however, the code I currently have has a ‘windup’ of sorts. (It’s not immediate) Is there any way to immediately shoot the player up when they touch a part?
The code:
tramp.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') ~= nil then
if db == false then
print(hit.Parent)
print(speed)
local attach = Instance.new('Attachment', hit.Parent.HumanoidRootPart)
local vecForce = Instance.new('VectorForce', hit.Parent.HumanoidRootPart)
vecForce.Attachment0 = attach
vecForce.Force = Vector3.new(0, speed*25, 0)
game.Debris:AddItem(attach, 0.5)
game.Debris:AddItem(vecForce, 0.5)
db = true
task.wait(0.5)
db = false
end
end
end)
I cannot get this to work, the player just doesn’t move. Here is the code. (Also sorry for the really late reply.
local tramp = script.Parent
local speed = tramp.Configuration.BounceSpeed.Value
local db = false
tramp.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') ~= nil then
if db == false then
db = true
hit:ApplyImpulse(Vector3.new(0, hit:GetMass() * speed, 0))
task.wait(1)
db = true
end
end
end)
The client always has network ownership of the character so you need to call ApplyImpulse from the client. I used this modified code and changed the scripts RunContext to client and it worked:
local tramp = script.Parent
local db = false
tramp.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') ~= nil then
if db == false then
db = true
print("boing")
hit.Parent.HumanoidRootPart:ApplyImpulse(Vector3.new(0, 1000, 0))
task.wait(1)
db = false
end
end
end)
You can remove the line task.wait(0.5) and make db a number instead of a boolean, and then check if it’s > tick(), e.g.:
local db = 0
tramp.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(‘Humanoid’) ~= nil then
if db < tick() then
print(hit.Parent)
print(speed)
local attach = Instance.new(‘Attachment’, hit.Parent.HumanoidRootPart)
local vecForce = Instance.new(‘VectorForce’, hit.Parent.HumanoidRootPart)
vecForce.Attachment0 = attach
vecForce.Force = Vector3.new(0, speed*25, 0)
game.Debris:AddItem(attach, 0.5)
game.Debris:AddItem(vecForce, 0.5)
db = tick() + 0.5
end
end
end)