I have a frame in a screenGui named "OreBar" in StarterGui, and when I try to access the frame with my script, I cannot find it. This is the error on line 4
It works in studio but NOT the game The script is not in screenGui, but it does access it.
The following script goes into workspace.ores:
function AddOre(player) --this goes in ore local ClickedOre = script.Parent local OreValue = ClickedOre.V.Value player.PlayerGui:WaitForChild("OreBar", 20) --NOT WORKING HELP local OreBar = player.PlayerGui.OreBar.Frame local CurrentOreSpot = nil for i=1,6,1 do if OreBar["Ore"..i].Text == "None" then CurrentOreSpot = OreBar["Ore"..i] break end end if CurrentOreSpot == nil then print("No more room!") return end ClickedOre.Position = Vector3.new(190, 100, -375) ClickedOre.Anchored = true CurrentOreSpot.Text = "This ore is $"..OreValue CurrentOreSpot.Ore.Value = ClickedOre end script.Parent.ClickDetector.MouseClick:connect(AddOre)
You can safely ignore ALL the CurrentOreSpot
junk, it is just part of the things inside OreBar
Without the time parameter in line 4 I get error:
Infinite yield possible for WaitForChild()
With it I get error after 10 seconds: cannot find OreBar in PlayerGui
. It is there. Ive made sure while playing the game in studio. This is the only script of 3 total scripts that modifiy OreBar
, another being a script inside OreBar
, and another is the intro to the game. None modify Name
property of OreBar
.
You say it's in screengui, if so it has to be a local script. Yet you have
The problem here is you need instead of:
script.Parent.ClickDetector.MouseClick:connect(AddOre)
which is meant for world objects in workspace. Gui's work differently which require MouseButton1Up, MouseButton1Down, MouseButton1Click, MouseButton2Down, MouseButton2Up, and MouseButton2Click, it should be:
script.Parent.MouseButton1Click:connect(AddOre)