How do i fix this?

I just started scripting and I’m in 5th grade so I’m not good I want to make when you step on a part a gui shows up and you can only exit it with a close button

this is the script to open this is the close button scriptclose here is the out put out put when i change the local player to my user it works but when the script is localplayer it doesn’t work this is the video I watched How To Make Popup Gui (Roblox Scripting) - YouTube hope someone can help me i want to learn to script

1 Like

and here is it working when i change the localplayer to my user namerobloxapp-20200829-1101043.wmv (1.2 MB)

1 Like

I’m guessing it’s a serverscript.
In that case, you can just do:

local Player = game.Players:GetPlayerFromCharacter(hit.Parent)

Player.PlayerGui.ScreenGui.Frame.Visible = true

I also suggest looking into Remote Events

3 Likes

Make sure that is a Local Script and not a Script. You can only use game.Players.LocalPlayer in a Local Script.

1 Like
     if hit.Parent:FinfFirstChild("Humanoid")    then
           game.Players.LocalPlayer.StarterGui.ScreenGui.Frame.Visible = true
end
end)

-- I'm not sure if this would work but I think you mean StarterGui instead of PlayerGui?

-- Also forgot to add that, you're gonna want this script to be a localscript.

It’s good to start young!

Okay, you should probably put your local script inside your GUI. Then you can reference the part from there.

local db = false --So that when somebody touches it, the GUI doesn’t pop up a million times.
local gui = script.Parent
local COOLDOWNTIME = (yournumber)

game.Workspace.(put your part here).Touched:Connect(function(toucher) --So that when the part is touched you can fire this.
  if toucher.Parent:FindFirstChild("Humanoid") and not db then --Tries to find if the person is a player by looking for a humanoid in it. If the cooldown is still on for that person, then they must wait for it to be off.
    db = true --turns on cooldown
    gui.Enabled = true --Turns on the GUI
    wait(COOLDOWNTIME)
    db = false
  end
end)
game.Workspace.(put your part here).TouchEnded:Connect(function(toucher) --When they stop touching it
  if toucher.Parent:FindFirstChild("Humanoid") and not db then --Tries to find if the person is a player by looking for a humanoid in it. If the cooldown is still on for that person, then they must wait for it to be off.
    db = true --turns on cooldown
    gui.Enabled = false -- Turns off the GUI
    wait(COOLDOWNTIME)
    db = false
  end
end)

I’m pretty sure he’s doing that in a ServerScript.
Also, that won’t work. Player’s don’t have a StarterGui inside of them.

It’s because you are using a variable that is only accesible via localscript
heres the script you should use

script.parent.Touched:connect(function(hit))
    if hit.Parent:FindFirstChild("Humanoid") then
        local Player = game.Players:FindFirstChild(hit)
        if Player then
            Player.PlayerGui.ScreenGui.Frame.Visible = true
            end
        end
    end
end)

sry i had to out fior a little it is a server script and ill try your sugggestains

do i put the local script inside the frame or the screengui

do i put the script inside the screengui or the frame bc when i put that script as a localScript inside screen gui nothing hapens when i step on the part

If you use game:GetService("Players").LocalPlayer it is possible.

It says it doesnt know what hit is in (hit.parent)

Can you send a photo of the error?

Also, are you doing:

hit.Parent

or

hit.parent

It needs to be hit.Parent

I’ll remake the code for ya.
You will need a:
CloseButton
Frame
ScreenGui
Part.
Make the screenGui. Make a frame inside of it, and make a button.
In the button, insert a local script.
type the following in it.

local Button = script.Parent
local ScreenGui = script.Parent.Parent.Parent ---- the button - frame - screengui.

Button.MouseButton1Click:Connect(function()
   ScreenGui.Enabled = false
end)

Now insert a RemoteEvent into replicated storage and call it : PartHitEvent
also, insert a part (the part you want to be touched) and put a script in it (A normal Script)
write this in the script:

local part = script.Parent
local RemoteEvent = game.ReplicatedStorage.PartHitEvent --- the remoteEvent

part.Touched:Connect(function(hit)
  if hit.Parent:FindFirstChild("Humanoid") then
     local Player = game.Players[hit.Parent.Name]
     RemoteEvent:FireClient(player)
   end
end)

Now go back into the local script and write those lines under the other function:

game.ReplicatedStorage.PartHitEvent.OnClientEvent:Connect(function()
   ScreenGui.Enabled = true
end)

This took me a while so enjoy!

1 Like