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 script here is the 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
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.
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)
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)
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
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: