Hey I have been trying to do a knockback system, where when a player clicks on another player, the target player is enflicted with knockback. I found some code on the devforum and modified and connected it to events. However the target won’t move and the output isn’t showing errors.
Here are the scripts:
--Local side
local mouse = game.Players.LocalPlayer:GetMouse()
local knockBackEvent = game.ReplicatedStorage.Events.KnockbackM
function getKnockback(hitPlayer)
local dir = mouse.UnitRay.Direction
knockBackEvent:FireServer(hitPlayer, dir)
end
mouse.Button1Down:Connect(function()
local hit = mouse.Target
if hit then
if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
getKnockback(hit.Parent)
end
end
end)
-- Server side
local knockBackEvent = game.ReplicatedStorage.Events.KnockbackM
local TweenService = game:GetService("TweenService")
function doKnockback(player, hitPlayer, dir)
local newCFrame = CFrame.new(hitPlayer.PrimaryPart.CFrame.Position)
newCFrame *= CFrame.Angles(dir.X, dir.Y, dir.Z)
newCFrame += newCFrame.LookVector * 20 --Arbitrary power amount
--Tween the player to that position.
end
knockBackEvent.OnServerEvent:Connect(doKnockback)