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

My code is a brick that you touch to open a gui then you touch another to close it?

Asked by 4 years ago
Edited 4 years ago

Sorry for the weird title, if you want a quick TL:DR on this it is about:

18:36:38.974 - FireClient: player argument must be a Player object

I would really appreciate some help here

Okay so I have a brick:

"RemoveGui" and inside there there is a script

01local brick = script.Parent
02brickClosedEvent = game.ReplicatedStorage.Event.BrickClose
03local debounce = false
04 
05brick.Touched:Connect(function(hit)
06    if not debounce then
07        debounce = true
08        print("activated")
09        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
10        brickClosedEvent:FireClient(player)
11        print("WorkingClose")
12        wait(0.5)
13        debounce = false
14    end
15end)

And I have another brick called "AddGui" which will show the gui, whereas RemoveGui will close it whcih goes

01local brick = script.Parent
02brickTouchedEvent = game.ReplicatedStorage.Event.BrickTouched
03local debounce = false
04 
05brick.Touched:Connect(function(hit)
06    if not debounce then
07        debounce = true
08        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
09        brickTouchedEvent:FireClient(player)
10        print("Working")
11        wait(0.5)
12        debounce = false
13    end
14end)

And then in replicated storage I have a folder called "Event" and inside that two remote events which are called "BrickClose" and "BrickTouched"


And finally in StarterGui I have got a local script called "BrickGui" which has a Gui called "Gui" and a frame inside that called "Frame".

So the local script (BrickGui) goes:

01local gui = script.Gui
02local brickTouchedEvent = game.ReplicatedStorage.Event.BrickTouched
03local brickCloseEvent = game.ReplicatedStorage.Event.BrickClose
04 
05 
06brickTouchedEvent.OnClientEvent:Connect(function()
07    gui.Enabled = true
08    print("open")
09end)
10 
11brickCloseEvent.OnClientEvent:Connect(function()
12    print("going to close")
13    gui.Enabled = false
14end)

So what I am aiming for is that the two remote events will fire and the local gui will pick them up and do so accordingly.


However


What my problem is that when I touch AddGui it says, "18:36:38.974 - FireClient: player argument must be a Player object"

I have read other articles on this but I can't really grasp what I should do.

I would really appreciate some help here, Thanks

2 answers

Log in to vote
0
Answered by
Subsz 366 Moderation Voter
4 years ago

What you're doing wrong inside your script is that you're not checking if the part that's touching it is a child of the character.

Here's how u can check that :

01brick.Touched:Connect(function(hit)
02    if hit.Parent:FindFirstChild('Humanoid') and not debounce then
03        debounce = true
04        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
05        brickTouchedEvent:FireClient(player)
06        print("Working")
07        wait(0.5)
08        debounce = false
09    end
10end)
0
Hi! Thanks for the quick reply, and sorry for my slow one, it still seems to not work but however this time it does not print anything in the output at all? L0rd_Zander -10 — 4y
0
Hm.. so it doesn't print 'Working' either? Subsz 366 — 4y
0
with your code no, but when i reverted it back to the original it does L0rd_Zander -10 — 4y
0
it might be the debounce then. Subsz 366 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

You can make the gui visible/invisible not removing or creating.That might fix your problem

Answer this question