I want to make a tool that flings people when they are clicked on.
The issue is that my code doesnt work, but it also doesnt throw any errors.
I have tried searching google, developer hub, and here.
I have code in a localscript and a serverscript, and i have tried dubbuging it, and nothing worked.
Im trying to get it to fling people in the direction the player is and very fast like. I also have that if the player is 4.5 studs or more away, it wont work.
LocalScript:
local mouse = game.Players.LocalPlayer:GetMouse()
script.Parent.Activated:Connect(function()
if mouse.Target then
local model = mouse.Target:FindFirstAncestorOfClass("Model")
if model then
if model:FindFirstChild("Humanoid") then
script.Parent.RemoteEvent:FireServer(model)
end
end
end
end)
And in my serverscript i have:
script.Parent.RemoteEvent.OnServerEvent:Connect(function(player,victim)
if (victim.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).magnitude <= 4.5 and not (player.Character:FindFirstChild("PushForce")) and not (victim:FindFirstChild("PushForce")) then
local PushForce = Instance.new("BodyVelocity")
PushForce.Name = "PushForce"
PushForce.MaxForce = Vector3.new(9999999999,999999999,999999999)
PushForce.Velocity = (-victim.HumanoidRootPart.CFrame.lookVector) * 100
PushForce.Parent = victim.HumanoidRootPart
wait(0.4)
PushForce:Destroy()
end
end)
Here’s a place file that you can try out yourself. Run the game with 2 players and click on the other player with the tool equipped. Fling Tool.rbxl (22.6 KB)
The only reason I can think of why it’s not working is because your tool’s .RequiresHandle property is enabled so it won’t register mouse input without a handle and won’t activate the .Activated event. I’m not sure why it’s not working for you since you said you ticked the .RequiresHandle property off