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
Hi, I'm BlackOrange and I will be helping you out.
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.