Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Using FindFirstChild to make a gui appear?

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

2 comments

0

There's supposed to be a ") on the end of GameOver. It is in the code.

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")

1 answer

✓ Accepted answer

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.

3 comments

0

Thanks! I'll try this when I have time and accept the answer if it works.

0

Thanks you so much! You just saved me and my game!

0

No Problem

This discussion is preserved as it was. New answers, comments, and votes are closed.