So I noticed today when I tested my game, that this function, that works in Studio, does not work. Any idea why? It is just a Script in Workspace, not a localscript.
wait(2) local ResourceManager = require(game.ReplicatedStorage.ResourceManager) local gui = game.Players.LocalPlayer.PlayerGui.PickupItemGui.ImageLabel for _,v in next,game.Workspace.Items:GetChildren()do v.ClickDetector.MouseClick:connect(function() local objectType = v.ObjectType.Value local data = ResourceManager.Resources[objectType] gui.TextLabel.Text = data.Name if gui.Visible == false then gui.Visible = true game.Players.LocalPlayer.PlayerGui.PickupItemGui.ImageLabel.ResourceType.Value = v.ObjectType.Value else end end) end
Ty!
Because you can't call LocalPlayer using a regular Script, that has to be done with a LocalScript.
http://wiki.roblox.com/index.php?title=API:Class/Players/LocalPlayer http://wiki.roblox.com/index.php?title=API:Class/LocalScript http://wiki.roblox.com/index.php?title=API:Class/Script
Here's the verison that should be working properly:
Wait(2) local ResourceManager = require(Game:GetService('ReplicatedStorage').ResourceManager) for _, V in pairs, Game:GetService('Workspace').Items:GetChildren() do V.ClickDetector.MouseClick:connect(function(Gui) if Gui:FindFirstChild('PlayerGui') and Gui.PlayerGui:FindFirstChild('PickupItemGui') and Gui.PlayerGui.PickupItemGui:FindFirstChild('ImageLabeli') then local Gui2 = Gui.PlayerGui.PickupItemGui.ImageLabel local objectType = V.ObjectType.Value local data = ResourceManager.Resources[objectType] Gui2.TextLabel.Text = data.Name if Gui2.Visible == false then Gui2.Visible = true Gui2.ResourceType.Value = V.ObjectType.Value else end end end) end
``
local ResourceManager = ReplicatedStorage:WaitForChild("ResourceManager") local gui = game.Players.LocalPlayer.PlayerGui.PickupItemGui.ImageLabel wait (2) for _,v in next,game.Workspace.Items:GetChildren()do v.ClickDetector.MouseClick:connect(function() local objectType = v.ObjectType.Value local data = ResourceManager.Resources[objectType] gui.TextLabel.Text = data.Name if gui.Visible == false then gui.Visible = true game.Players.LocalPlayer.PlayerGui.PickupItemGui.ImageLabel.ResourceType.Value = v.ObjectType.Value else end end) end