local remote = game.ReplicatedStorage:WaitForChild("Hitted1")
remote.OnServerEvent:Connect(function(target , mouseCFrame)
if target then
if target.Parent:FindFirstChild("Humanoid") then
local lookVector = mouseCFrame.LookVector --Gets mouse CFrame
if mouseCFrame.LookVector.Y < 0 then
lookVector = mouseCFrame.LookVector * Vector3.new(1,-1,1) --This is only to make player knockback upwards, and not downwards. You can remove this if you want.
end
local root = target.Parent.HumanoidRootPart
local velocity = Instance.new("BodyVelocity")
print("Hit"..target.Name)
velocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
velocity.P = 1500
velocity.Velocity = (target.HumanoidRootPart.CFrame.LookVector * -1) * 100
velocity.Parent = root
wait(0.5)
velocity:Destroy()
--- server script ^
end
end
end)
local script code:
local tool = script.Parent
local remote = game.ReplicatedStorage:WaitForChild("Hitted1")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
tool.Activated:Connect(function()
remote:FireServer(mouse.Target, true, "ErrorPart Equipped")
end)
--- local script ^
script above is not working
it’s supposed to knockback the target player
no errors
any help will work and post with the script
No errors right? Then let’s relook at what you’re trying to do here. Basically, you are detecting inputs from the user and use a RemoteEvent to add BodyVelocity to the target if it is a valid character with a Humanoid.
Alright, if you’re not testing it with someone, then it means you’re testing it with a NPC. Have you checked if the NPC is anchored? If the NPC is anchored, force such as BodyVelocity will not work on the NPC. (when i spawn npc from roblox studio, the humanoidrootpart is usually anchored, so check that)
I think it’s also because you’re passing over the following datatypes when firing the remote: :FireServer(BasePart?, boolean, string)
When the server accepts :Connect(function(BasePart?, CFrame)
Basically, you should instead fire the remote with :FireServer(mouse.Target, mouse.Hit)
--LOCAL
local replicated = game:GetService("ReplicatedStorage")
local remote = replicated:WaitForChild("Hitted1")
local players = game:GetService("Players")
local player = players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent
tool.Activated:Connect(function()
if mouse.Target then
remote:FireServer(mouse.Target, mouse.Hit)
end
end)
--SERVER
local replicated = game:GetService("ReplicatedStorage")
local remote = replicated.Hitted1
remote.OnServerEvent:Connect(function(player, mouseTarget, mouseHit)
local targetModel = mouseTarget:FindFirstAncestorOfClass("Model")
if targetModel then
local targetHuman = targetModel:FindFirstChildOfClass("Humanoid")
if targetHuman then
local targetRoot = targetModel:FindFirstChild("HumanoidRootPart")
if targetRoot then
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bodyVelocity.P = 1500
bodyVelocity.Velocity = (-targetRoot.CFrame.UpVector) * 100
bodyVelocity.Parent = targetRoot
task.wait(0.5)
bodyVelocity:Destroy()
end
end
end
end)
This is working for me (assuming you wanted to create a fling tool).