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?
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