Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What can I use as a replacement for MouseButton1Click?

This is my code:

script.Parent.confirm.MouseButton1Click:connect(function(player)
    game.ReplicatedStorage.GiveRoom:FireServer(player)
end)

I have FilteringEnabled on in this game. But FilteringEnabled does not allow MouseButton1Click to be called. How can I get around this?

4 comments

0

weird, i tried using mousebutton1click for my game, and it worked. are you sure you're using a localscript?

0

What do you mean, filtering enabled doesn't affect mouse related events if ur using it properly.

0

FilteringEnabled has nothing to do with this. It is most likely a problem with your RemoteEvent.

0

I'm assuming this is a BillboardGui or a SurfaceGui, if you're having issues with it. You'll need to use Adornee, if this is the problem.

2 answers

✓ Accepted answer

If this is not in a local script then that is the problem. It must be in a local script. If it is in a local script, here is why it is not working:

script.Parent.confirm.MouseButton1Click:connect(function(player)
	game.ReplicatedStorage.GiveRoom:FireServer(player)
end)

A local script does not need to detect the player that clicked a button when the only player that could have is it's client, so you do not need the player argument.

It should look like this: (also remember to use :Connect because :connect is deprecated)

script.Parent.confirm.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.GiveRoom:FireServer()
end)

And in the server: (example script)

game.ReplicatedStorage.GiveRoom.OnServerEvent:Connect(function(player)
	 -- Whatever code you need to run goes here
end)

Note that the event function still has the player argument, because the first argument in any remote event or function server side is always the player it came from, if you want to get data from the client do it like this:

(EXAMPLE)

game.ReplicatedStorage.GiveRoom.OnServerEvent:Connect(function(player,data)
	print(player.." said: "..data);
end)

And call it like this from a client:

script.Parent.confirm.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.GiveRoom:FireServer("Hello World!");
end)

Use MouseButton1Down

1 comment

2

This should've been put in the comments, not in an answer reply.

This discussion is preserved as it was. New answers, comments, and votes are closed.