Hi!
I am trying to have it so when a player touches a part a gui shows up, but it’s not working.
I’ve tried looking online and I can’t find anything to help. sorry if I’m missing something obvious, im like rlly new to this. tysm in advance
local touchpart = game.Workspace:WaitForChild("school for unidenified faries")
local bg = script.Parent
local exit = screenGui:WaitForChild("exit_button")
local farm = screenGui:WaitForChild("farmingmode")
local mode = screenGui:WaitForChild("modeselection_text")
local rp = screenGui:WaitForChild("rpmode")
local story = screenGui:WaitForChild("storymode")
touchpart.Touched:Connect(function(touch)
if touch.Parent:FindFirstChild("Humaniod") and touch.Parent == game.Players.LocalPlayer.Character then
bg.Visible = true
exit.Visible = true
farm.Visible = true
mode.Visible = true
rp.Visible = true
story.Visible = true
print("Gui opened")
end
end)
No I wouldn’t approach this in that way.
I would make a localscript in “StarterPlayerScripts” that is attached to the player.
SO you can call things like this:
local Player = Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local Gui = PlayerGui:WaitForChild("<putyourguinamehere>")
local Frame = Gui.Frame
-attach it to a touched event
local function SetupModels()
for _, descendant in Workspace:GetDescendants() do
if descendant.Name == "school for unidenified faries" then
descendant.PrimaryPart.Touched:Connect(function(otherPart)
local player = Players:GetPlayerFromCharacter(otherPart.Parent)
if player == Player and not Gui.Enabled then
Gui.Enabled = true
end
end)
end
end
end
Hope this helps, but know you have to call certain things that I did not add to most local scripts. My goal is to give you a part of what you need to get you in the RIGHT direction. Then you can use this information above to find a solution. For example this script needs local Workspace = game:GetService(“Workspace”)
Also my advice for you in the future: don’t put scripts into a part, or a NPC or anything like that. Everything can be handled server side. It isn’t good practice and can lead to unwanted activity.
ok, this is the code I think should work but it doesn’t and I keep on getting this error:
Infinite yield possible on ‘Players.iiKhico.PlayerGui.ScreenGui:WaitForChild(“Frame”)’
local Player = Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local Gui = PlayerGui:WaitForChild("bg")
local exit = PlayerGui:WaitForChild("exit_button")
local farm = PlayerGui:WaitForChild("farmingmode")
local mode = PlayerGui:WaitForChild("modeselection_text")
local rp = PlayerGui:WaitForChild("rpmode")
local story = PlayerGui:WaitForChild("storymode")
local Frame = Gui.Frame
local Workspace = game:GetService(“Workspace”)
--attach it to a touched event
local function onTouch(hit)
for _, descendant in Workspace:GetDescendants() do
if descendant.Name == "school for unidenified faries" then
descendant.PrimaryPart.Touched:Connect(function(otherPart)
local player = Players:GetPlayerFromCharacter(otherPart.Parent)
if player == Player and not Gui.Enabled then
Gui.Enabled = true
exit.Visible = true
farm.Visible = true
mode.Visible = true
rp.Visible = true
story.Visible = true
end
end)
end
end
end
That’s from this line: local Frame = Gui.Frame It basically means Frame has not been found or will not be found if it doesn’t exist, can you screenshot the explorer of what your trying to access on that line?
Ah check your original script, I got confused on the new one, but you misspelled humanoid
local touchpart = game.Workspace:WaitForChild("school for unidenified faries")
local bg = script.Parent
local exit = screenGui:WaitForChild("exit_button")
local farm = screenGui:WaitForChild("farmingmode")
local mode = screenGui:WaitForChild("modeselection_text")
local rp = screenGui:WaitForChild("rpmode")
local story = screenGui:WaitForChild("storymode")
touchpart.Touched:Connect(function(touch)
if touch.Parent:FindFirstChild("Humanoid") and touch.Parent == game.Players.LocalPlayer.Character then
bg.Visible = true
exit.Visible = true
farm.Visible = true
mode.Visible = true
rp.Visible = true
story.Visible = true
print("Gui opened")
end
end)
Copy and paste this script back to how you had it when you made this post but with this change I made, it should work
Alright, once your done with that if you’d like to show me what the entire full code that’s erroring from this topic is currently at so I can just get a solid script from the current standpoint to look through, I’ll look through it again, and see what I can do
local Player = Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local touchpart = game.Workspace:WaitForChild("school for unidenified faries")
local bg = script.Parent
local exit = screenGui.modeselectionforunidenifiedfairies("exit_button")
local farm = screenGui.modeselectionforunidenifiedfairies("farmingmode")
local mode = screenGui.modeselectionforunidenifiedfairies("modeselection_text")
local rp = screenGui.modeselectionforunidenifiedfairies("rpmode")
local story = screenGui.modeselectionforunidenifiedfairies("storymode")
touchpart.Touched:Connect(function(touch)
if touch.Parent:FindFirstChild("Humanoid") and touch.Parent == game.Players.LocalPlayer.Character then
bg.Visible = true
exit.Visible = true
farm.Visible = true
mode.Visible = true
rp.Visible = true
story.Visible = true
print("Gui opened")
end
end)
this is a screen shot of the error msgs from this script:
local Player = game.Players.LocalPlayer This is the first line right? I edited it right after I sent it because originally I was being dumb, and made a dumb mistake