Im not sure if this type of question is ok, but I really have no clue on how to do this. Basically, im trying to make an ability for a sword when you press e, it knocks the opponent in front back. But I don't really know how to do this. I would REALLY appreciate help.
here is the script in server script service, which gets activated when the remote gets fired from the sword:
game.ReplicatedStorage.Bat.OnServerEvent:Connect(function(player) local char = player.Character local bat = char:FindFirstChild("Bat") wait(1.2) bat.Handle.Bonk:Play() bat.Handle.bat_hit:Play() bat.Handle.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then if hit.Parent.Name ~= player.Name then hit.Parent.Humanoid:TakeDamage(3) end end end) end
I answered a question 2 days ago asking "How to make an egg launcher like in the egg hunts?" and I have a similar answer here for you.
BodyForce IS deprecated, but it still works.
We just have to do a quick copy 'n paste with that code aaaand...
game.ReplicatedStorage.Bat.OnServerEvent:Connect(function(player,bat) local debounce = false local char = player.Character bat.Handle.Bonk:Play() bat.Handle.bat_hit:Play() bat.Handle.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then if hit.Parent.Name ~= player.Name then if debounce == false then debounce = true local force = Instance.new("BodyForce",hit.Parent.HumanoidRootPart) force.Force = bat.Handle.CFrame.lookVector * 10500 -- Change this depending on how far you want people to go hit.Parent.Humanoid:TakeDamage(25) game.Debris:AddItem(force,.5) end end end end) end -- Change this to end) or your script won't work at all.
ALSO! I have some changes. I added a debounce, a 'bat' argument, and, well, the force. I also upped the damage.
We also have a client change. Insert a LocalScript INSIDE the tool, not inside the handle but the TOOL.
Then add:
local plr = game.Players.LocalPlayer script.Parent.Activated:Connect(function() game.ReplicatedStorage.Bat:FireServer(script.Parent) end)
This is simple, the bat remote event fires an argument of our bat. Adding the player is not needed, since this is the client.
I won't get down in big details, but if you would like me to, go ahead.