Help with Mouse.Button1Down

So i’m working on a little project called rope ragdoll and I’ve made it so whenever you click somewhere on a part, you are able to ragdoll and get attached to the place you’ve clicked on.

The problem I’m having is that I added a pizza giver tool, which I’d like to use however, when using the tool, depending on whever you clicked, you get roped onto the area you’ve clicked at.
Not only that, even when clicking on the clickdetector causes you to be roped at the place you’ve clicked at too.

Basically, I’d like a way to prevent have the player become roped and ragdolled when clicking on a clickdetector or using a tool.

Here’s the script for the mouseclick

	local target = Mouse.Target
	local pos = Mouse.Hit
	if Player.Character.Humanoid.Health ~= 0 and Player:DistanceFromCharacter(pos.Position) < 25 then
		game.ReplicatedStorage.delRope:FireServer()
		game.ReplicatedStorage.addRope:FireServer(pos, target)
		game.ReplicatedStorage.Ragdoll:FireServer()
	end
end)

if you’d like to see the game, you can do so here

Is this the whole script? The Mouse variable/parameter isn’t specified within the provided code.

my bad, here you go

repeat wait() until script.Parent.Parent:IsA("Player")

local Player = script.Parent.Parent
local Mouse = Player:GetMouse()

Mouse.Button1Down:Connect(function()
	local target = Mouse.Target
	local pos = Mouse.Hit
	if Player.Character.Humanoid.Health ~= 0 and Player:DistanceFromCharacter(pos.Position) < 25 then
		game.ReplicatedStorage.delRope:FireServer()
		game.ReplicatedStorage.addRope:FireServer(pos, target)
		game.ReplicatedStorage.Ragdoll:FireServer()
	end
end)
1 Like

Where is the script located, can I see the explorer? Are you also getting any errors?

its a local script in the startpack

no, no errors, the problem is that whenever i click using a tool or click on a clickdetector, it ropes and ragdolls me, i’d like for it not to do that since it’s quite annoying

Have you tried of comparing the mouse origin and the player part that your mouse is indexing and if the names are similar, return the function?

you mean if the part that the mouse clicks on is the parent of a clickdetector, it should just ignore it?

1 Like

Try this:

local target = Mouse.Target
	local pos = Mouse.Hit
    if Player.Character:FindFirstChildOfClass('Tool') or Mouse.Target:IsA('ClickDetector') then return end
	if Player.Character.Humanoid.Health ~= 0 and Player:DistanceFromCharacter(pos.Position) < 25 then
		game.ReplicatedStorage.delRope:FireServer()
		game.ReplicatedStorage.addRope:FireServer(pos, target)
		game.ReplicatedStorage.Ragdoll:FireServer()
	end
end)

that worked, just had to change the bit for when you click on the clickdetector

Mouse.Button1Down:Connect(function()
	local target = Mouse.Target
	local pos = Mouse.Hit
	if Player.Character:FindFirstChildOfClass('Tool') or Mouse.Target:FindFirstChildOfClass("ClickDetector") then return end
	if Player.Character.Humanoid.Health ~= 0 and Player:DistanceFromCharacter(pos.Position) < 25 then
		game.ReplicatedStorage.delRope:FireServer()
		game.ReplicatedStorage.addRope:FireServer(pos, target)
		game.ReplicatedStorage.Ragdoll:FireServer()
	end
end)

thanks.

1 Like