Hello, I was building a brick(CanCollideFalse) where if you step in, a value becomes true, and if you step out, the value becomes false. The below script works perfectly in Studio Test Mode:
script.Parent.Touched:connect(function(Hit) local Player = game.Players:GetPlayerFromCharacter(Hit.Parent) if Player then Player.PlayerGui.ComputerGui.Battery.change.charging.Value = true end end) script.Parent.TouchEnded:connect(function(out) local Player = game.Players:GetPlayerFromCharacter(out.Parent) if Player then Player.PlayerGui.ComputerGui.Battery.change.charging.Value = false end end)
... however fails in game with an error stating that on Line 4 and 11: ComputerGui is not a valid member of PlayerGui (when ComputerGui is clearly a child of PlayerGui.)
Maybe it's an issue with Player not being the parent of PlayerGui?
Here's a pic of my StarterGui: http://tinypic.com/r/2qceb7o/9
Scripts can't acces PlayerUI. You'll have to fire a RemoteEvent, which a localscript will trigger from. This way, you can tell a specific client, to do something, so the server doesn't have to do it. (You most likely want to handle anything UI related to the client.)
Example:
--script Part.Touched:Connect(function(a) --Check if player if game.Players:GetPlayerFromCharacter(a.Parent) then --The "true" here, is "state" in the localscript. (First argument) game.ReplicatedStorage.RemoteEvent:FireClient(game.Players[a.Parent.Name], true) end end) Part.TouchEnded:Connect(function(a) --Check if player if game.Players:GetPlayerFromCharacter(a.Parent) then --The "false" here, is "state" in the localscript. (First argument) game.ReplicatedStorage.RemoteEvent:FireClient(game.Players[a.Parent.Name], false) end end) --localscript game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(state) game.Players.LocalPlayer.PlayerGui.ComputerGui.Battery.change.charging.Value = state end) --Structure --[[ game -Workspace --Part ---Script -ReplicatedStorage --RemoteEvent -StarterGui --LocalScript --ComputerGui ]] --I haven't tested this code, so if anything errors, or something unexpected happens, feel free to comment on it.