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.
01 | wait( 2 ) |
02 | local ResourceManager = require(game.ReplicatedStorage.ResourceManager) |
03 | local gui = game.Players.LocalPlayer.PlayerGui.PickupItemGui.ImageLabel |
04 |
05 | for _,v in next ,game.Workspace.Items:GetChildren() do |
06 | v.ClickDetector.MouseClick:connect( function () |
07 | local objectType = v.ObjectType.Value |
08 | local data = ResourceManager.Resources [ objectType ] |
09 | gui.TextLabel.Text = data.Name |
10 | if gui.Visible = = false then |
11 | gui.Visible = true |
12 | game.Players.LocalPlayer.PlayerGui.PickupItemGui.ImageLabel.ResourceType.Value = v.ObjectType.Value |
13 | else |
14 | end |
15 | end ) |
16 | 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:
01 | Wait( 2 ) |
02 | local ResourceManager = require(Game:GetService( 'ReplicatedStorage' ).ResourceManager) |
03 |
04 | for _, V in pairs , Game:GetService( 'Workspace' ).Items:GetChildren() do |
05 | V.ClickDetector.MouseClick:connect( function (Gui) |
06 | if Gui:FindFirstChild( 'PlayerGui' ) and Gui.PlayerGui:FindFirstChild( 'PickupItemGui' ) and Gui.PlayerGui.PickupItemGui:FindFirstChild( 'ImageLabeli' ) then |
07 | local Gui 2 = Gui.PlayerGui.PickupItemGui.ImageLabel |
08 | local objectType = V.ObjectType.Value |
09 | local data = ResourceManager.Resources [ objectType ] |
10 | Gui 2. TextLabel.Text = data.Name |
11 | if Gui 2. Visible = = false then |
12 | Gui 2. Visible = true Gui 2. ResourceType.Value = V.ObjectType.Value |
13 | else |
14 | end |
15 | end |
16 | end ) |
17 | end |
1 | <pre class = "brush: lua" >`` |
2 | </pre> |
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