Hello, i want to make push tool when the handle hits human then it will push him
my script don’t work for some reason if someone can help me and explain to me i will appreciate a lot
The first argument for .OnServerEvent is the player who fired it, not your first argument
BodyVelocity.Velocity takes in a Vector3
Also, scripts don’t run in ReplicatedStorage.
New server code:
local pushPower = 100000
script.Parent.Push.OnServerEvent:Connect(function(player, otherCharacter)
if not otherCharacter or typeof(otherCharacter) ~= "Instance" then
return
end
local humanoidRootPart = otherCharacter:FindFirstChild("HumanoidRootPart")
if not humanoidRootPart then
return
end
humanoidRootPart:ApplyImpulse(player.Character.HumanoidRootPart.CFrame.LookVector * pushPower)
end)
its work but now i have other problem, i want it to push him when he touch it and the tool is activated
like when i click the mouse and the player touch it, it will push him
--//Variables
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local Push = Tool:WaitForChild("Push")
--//Controls
local pushDuration = 3
local debounce = false
--//Tables
local Connections = {}
--//Functions
Tool.Activated:Connect(function()
if debounce then
return
end
debounce = true
Connections.Pushed = Handle.Touched:Connect(function(hit)
Push:FireServer(hit.Parent)
end)
task.wait(pushDuration)
local connection = Connections.Pushed
if connection then
connection:Disconnect()
Connections.Pushed = nil
end
task.wait(1)
debounce = false
end)
This will activate the push for 3 seconds when the player clicks, and then disable it after.
local Players = game:GetService("Players")
local pushPower = 100000
script.Parent.Push.OnServerEvent:Connect(function(player, otherCharacter)
if not otherCharacter or typeof(otherCharacter) ~= "Instance" then
return
end
local humanoidRootPart = otherCharacter:FindFirstChild("HumanoidRootPart")
if not humanoidRootPart then
return
end
for i, descendant in ipairs(otherCharacter:GetDescendants()) do
if not descendant:IsA("BasePart") then
continue
end
descendant:SetNetworkOwner(nil)
end
humanoidRootPart:ApplyImpulse(player.Character.HumanoidRootPart.CFrame.LookVector * pushPower)
local otherPlayer = Players:GetPlayerFromCharacter(otherCharacter)
if otherPlayer then
task.wait(2)
for i, descendant in ipairs(otherCharacter:GetDescendants()) do
if not descendant:IsA("BasePart") then
continue
end
descendant:SetNetworkOwner(otherPlayer)
end
end
end)
--//Variables
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local Push = Tool:WaitForChild("Push")
--//Controls
local pushDuration = 3
local debounce = false
--//Tables
local Connections = {}
--//Functions
Tool.Activated:Connect(function()
if debounce then
return
end
debounce = true
local coolAnimation = Tool.Parent.Humanoid.Animator:LoadAnimation(workspace.MyCoolAnimation)
coolAnimation:Play()
Connections.Pushed = Handle.Touched:Connect(function(hit)
Push:FireServer(hit.Parent)
end)
task.wait(pushDuration)
local connection = Connections.Pushed
if connection then
connection:Disconnect()
Connections.Pushed = nil
end
task.wait(1)
debounce = false
end)
local Players = game:GetService("Players")
local pushPower = 100000
script.Parent.Push.OnServerEvent:Connect(function(player, otherCharacter)
if not otherCharacter or typeof(otherCharacter) ~= "Instance" then
return
end
local humanoidRootPart = otherCharacter:FindFirstChild("HumanoidRootPart")
if not humanoidRootPart then
return
end
for i, descendant in ipairs(otherCharacter:GetDescendants()) do
if not descendant:IsA("BasePart") or descendant.Anchored then
continue
end
descendant:SetNetworkOwner(nil)
end
humanoidRootPart:ApplyImpulse(player.Character.HumanoidRootPart.CFrame.LookVector * pushPower)
local otherPlayer = Players:GetPlayerFromCharacter(otherCharacter)
if otherPlayer then
task.wait(2)
for i, descendant in ipairs(otherCharacter:GetDescendants()) do
if not descendant:IsA("BasePart") or descendant.Anchored then
continue
end
descendant:SetNetworkOwner(otherPlayer)
end
end
end)
local Players = game:GetService("Players")
local pushPower = 100000
script.Parent.Push.OnServerEvent:Connect(function(player, otherCharacter)
if not otherCharacter or typeof(otherCharacter) ~= "Instance" then
return
end
local humanoidRootPart = otherCharacter:FindFirstChild("HumanoidRootPart")
if not humanoidRootPart then
return
end
for i, descendant in ipairs(otherCharacter:GetDescendants()) do
if not descendant:IsA("BasePart") or descendant.Anchored then
continue
end
descendant:SetNetworkOwner(nil)
end
for index, joint in pairs(otherCharacter:GetDescendants()) do
if joint:IsA("Motor6D") then
local socket = Instance.new("BallSocketConstraint")
local a1 = Instance.new("Attachment")
local a2 = Instance.new("Attachment")
a1.Parent = joint.Part0
a2.Parent = joint.Part1
socket.Parent = joint.Parent
socket.Attachment0 = a1
socket.Attachment1 = a2
a1.CFrame = joint.C0
a2.CFrame = joint.C1
socket.LimitsEnabled = true
socket.TwistLimitsEnabled = true
joint:Destroy()
end
end
humanoidRootPart:ApplyImpulse(player.Character.HumanoidRootPart.CFrame.LookVector * pushPower)
local otherPlayer = Players:GetPlayerFromCharacter(otherCharacter)
if otherPlayer then
task.wait(2)
for i, descendant in ipairs(otherCharacter:GetDescendants()) do
if not descendant:IsA("BasePart") or descendant.Anchored then
continue
end
descendant:SetNetworkOwner(otherPlayer)
end
end
end)