Tool not working

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)

Any help is greatly appreciated!

Try this out.

script.Parent.RemoteEvent.OnServerEvent:Connect(function(player, victim)
    local difVector = player.Character.HumanoidRootPart.Position - victim.HumanoidRootPart.Position
    if difVector.Magnitude <= 4.5 then
        local PushForce = Instance.new("BodyVelocity")
        PushForce.Name = "PushForce"
        PushForce.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
        PushForce.Velocity = difVector.Unit * 100
        PushForce.Parent = victim.HumanoidRootPart
        wait(.4)
        PushForce:Destroy()
    end
end)

If the force goes the opposite direction you want it to, use

PushForce.Velocity = -difVector.Unit * 100
1 Like

Tick the tool.RequiresHandle property off and it should work.

The tool.RequiresHandle property is off though.

It works for me, are you sure you’re equipping the tool then walking really close to the target player and then clicking them?

1 Like

I just tried it, (with R6 and R15) and it still did not work. It just did the same thing, nothing.

Could you put a print statement in the serverside code and see if it prints when the player clicks?

1 Like

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)

1 Like

I just added that, and it appears not to print anything for some reason (at all).

Alright, that gives me good info. Hold on and I’ll see if I can rewrite the local script.

1 Like

My roblox studio is being mad, and it just gives me an error while opening the place file, but yet i cant post bug reports yet. :frowning:

Can you put a print in the local script and see if it’s firing the event at all?

1 Like

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

Im sure that it says its off, im positive.

Okay so i just did that and… its not firing at all.

Is the Activated event being triggered?

No, the Activated event isnt being triggered.

Can you put a print on the first line of the localscript to see if the script is even running?

1 Like

Yep, the script sure is running.

Hm, not sure what could be going on here. You could upload a model file of the tool so I can inspect it closer.

1 Like