Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What can I use as a replacement for MouseButton1Click?

Asked by 7 years ago

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?

0
weird, i tried using mousebutton1click for my game, and it worked. are you sure you're using a localscript? V_ChampionSSR 247 — 7y
0
What do you mean, filtering enabled doesn't affect mouse related events if ur using it properly. IcedVapour 153 — 7y
0
FilteringEnabled has nothing to do with this. It is most likely a problem with your RemoteEvent. 4xN 10 — 7y
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. Pyrondon 2089 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago

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)
Ad
Log in to vote
-1
Answered by 7 years ago

Use MouseButton1Down

2
This should've been put in the comments, not in an answer reply. awfulszn 394 — 7y

Answer this question