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

Using FindFirstChild to make a gui appear?

Asked by 6 years ago

I'm trying to make it so when you touch a part it makes a GUI appear but it comes up with this error: "Argument 1 missing or nil"

Here's the code:

local gui = game.Players:FindFirstChild():WaitForChild("StarterGui"):WaitForChild("GameOver")
    gui.Frame.Visible = true
0
There's supposed to be a ") on the end of GameOver. It is in the code. Escaper65 6 — 6y
0
I'm pretty sure you missed out the argument in FindFirstChild(argument). You should probably replace argument with the player's name: FindFirstChild("Escaper65") GoldAngelInDisguise 297 — 6y

1 answer

Log in to vote
3
Answered by 6 years ago
Edited 6 years ago

Hi, I'm BlackOrange and I will be helping you out.

Problem:

  1. You did not specify what type of script this is
  2. You're looking in the wrong place.
  3. You need RemoteEvents

Solution:

A simple solution is to restart. First add a RemoteEvent to ReplicatedStorage. You can name it anything you want but I'm going to leave it as RemoteEvent. Next, go to your part and insert a Script. Inside the script you wanna start by a Touched event:

script.Parent.Touched:Connect(function(Hit) -- Assuming script.Parent is a part

end)

Now what you wanna do is add a LocalScript into the frame you want to appear. After that go to the LocalScript and type:

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function() -- When the client receives a FireClient from the server the code will run
    script.Parent.Visible = true -- Make the frame visible
end)

Now head back to the script and what you wanna do is get the player. The method we are going to use is :GetPlayerFromCharacter(). First we want to check if a player touched the part though.

script.Parent.Touched:Connect(function(Hit)
    if Hit:IsA('BasePart') and Hit.Parent:IsA('Model') and Hit.Parent:FindFirstChild('Humanoid') and game.Players:FindFirstChild(Hit.Parent.Name) then -- This is a fairly long line but this checks if this there is a humanoid and if it's a player.
        local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)-- get's the player
        game.ReplicatedStorage.RemoteEvent:FireClient(Player) -- sends a signal to the player
    end
end)

And you're done! Hope you learned something.

Best of luck developer!

EDIT: This was written from scratch, if an issue occurs please comment.

0
Thanks! I'll try this when I have time and accept the answer if it works. Escaper65 6 — 6y
0
Thanks you so much! You just saved me and my game! Escaper65 6 — 6y
0
No Problem BlackOrange3343 2676 — 6y
Ad

Answer this question