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

local brick = script.Parent
brickClosedEvent = game.ReplicatedStorage.Event.BrickClose
local debounce = false

brick.Touched:Connect(function(hit)
    if not debounce then
        debounce = true
        print("activated")
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        brickClosedEvent:FireClient(player)
        print("WorkingClose")
        wait(0.5)
        debounce = false
    end
end)

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

local brick = script.Parent
brickTouchedEvent = game.ReplicatedStorage.Event.BrickTouched
local debounce = false

brick.Touched:Connect(function(hit)
    if not debounce then
        debounce = true
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        brickTouchedEvent:FireClient(player)
        print("Working")
        wait(0.5)
        debounce = false
    end
end)

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:

local gui = script.Gui
local brickTouchedEvent = game.ReplicatedStorage.Event.BrickTouched
local brickCloseEvent = game.ReplicatedStorage.Event.BrickClose


brickTouchedEvent.OnClientEvent:Connect(function()
    gui.Enabled = true
    print("open")
end)

brickCloseEvent.OnClientEvent:Connect(function()
    print("going to close")
    gui.Enabled = false
end)

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 :

brick.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild('Humanoid') and not debounce then
        debounce = true
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        brickTouchedEvent:FireClient(player)
        print("Working")
        wait(0.5)
        debounce = false
    end
end)
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