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

FireClient: player argument must be a Player object?

Asked by
sallyVS 15
4 years ago
Edited 4 years ago

I'm trying to fire from server to client. The part I have in the workspace:

Workspace
    Part
        Script
        TextButton

And in the StarterGui:

StarterGui
    ScreenGui
        Frame
        LocalScript

The Script:

local button = script.Parent.TextButton
local remEvent = game:GetService("ReplicatedStorage").RemoteEvent

button.MouseButton1Click:Connect(function(player)
    remEvent:FireClient(player)
end)

The LocalScript:

local remEvent = game:GetService("ReplicatedStorage").RemoteEvent

remEvent.OnClientEvent:Connect(function(player)
    script.Parent.Frame.Visible = true
end)

So when a player clicks the text button I wan't the Frame to become visible for the player. The server script doesn't seem to understand what the player is, though I have to put the player there or I get an error "Argument 1 missing or nil". I have thought that I could maybe define the player with a "PlayerAdded" function, but I'm not sure if I want to use it there even if it works.

2 answers

Log in to vote
0
Answered by
Norbunny 555 Moderation Voter
4 years ago

You can't get the player who clicked the SurfaceGUI's button from the server! You should parent the SurfaceGUI to the StarterGUI, and to make it visible on the part, set the GUI's adornee to the part!

From there, you can just listen to the click, and make it invisible for the player, without needing to use a RemoteEvent since that your code is fully client sided!

-- Local script inside of the GUI
local button = script.Parent.TextButton

-- You connect to the mouse click and make the GUI invisible in the same script!
button.MouseButton1Click:Connect(function() 
    script.Parent.Frame.Visible = false
end)
1
Thank you so much!! sallyVS 15 — 4y
0
Happy to help! Norbunny 555 — 4y
Ad
Log in to vote
1
Answered by
sallyVS 15
4 years ago

I think I solved it... kind of. My script worked with a Click Detector, but not with the text buttons, but I don't know why it is like that :/

0
Check my reply, I'm sorry that I'm a bit late! The ClickDetector is a nice workaround, but you can make it simpler by just doing what I said! Norbunny 555 — 4y

Answer this question