I’ve been trying to do this so simple thing for a few days now, the example from the documentation doesn’t work, the scripts from the assistant don’t work, it’s strange because when the script applies an impulse after pressing a key on the keyboard then everything works nice, only not when I set it in the onTouch script in the object.
This one is from documentation;
local volume = script.Parent
local function onTouched(other)
local impulse = Vector3.new(0, 2500, 0)
local character = other.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
if humanoid and other.Name == "LeftFoot" then
other:ApplyImpulse(impulse)
print("touched")
end
end
volume.Touched:Connect(onTouched)
Knockback with humanoids is actually 3 times as hard as you need to account for humanoid counterforces (the resist force) and network ownership. So the steps for a local script will be different.
Here is an example with .AssemblyLinearVelocity you can swap it out with apply impulse as well it will achieve a similar effect.
I made this way I created RemoteEvent, then in script under touched part I wrote
local reevent = game.ReplicatedStorage.REimpuls
local part = script.Parent
local touchOnce = 1
part.Touched:Connect(function(characterpart)
local character = characterpart.Parent
if character:FindFirstChild("Humanoid") and touchOnce == 1 then
touchOnce = 0
local player = game.Players:GetPlayerFromCharacter(character)
reevent:FireClient(player)
task.wait(5)
touchOnce = 1
end
end)
and in localscript under StarterPlayerScripts I wrote
local reevent = game.ReplicatedStorage.REimpuls
reevent.OnClientEvent:Connect(function()
local player = game.Players.LocalPlayer
local character = player.Character
local impulse = Vector3.new(0, 1500, 0)
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
if humanoid then
character.HumanoidRootPart:ApplyImpulse(impulse)
end
end)