This script works in regular studio testing mode, but not ingame. Any help? I'm getting the error ScreenGui is not a valid member of PlayerGui on line 6.
script.Parent.Hitbox.Touched:connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if hit.Parent:FindFirstChildWhichIsA("Humanoid") ~= nil then
if player.CarryingB.Value == false then
player.CarryingB.Value = true
player.PlayerGui.ScreenGui.Battery:TweenPosition(UDim2.new(0.85, 0, 0, 0), "Out", "Sine", 1)
script.Parent:Destroy()
end
end
end)

10 comments
if it is a ServerScript, change it to a LocalScript.
still not working
Try changing the name "ScreenGui" to something else.
try for the variable player.. game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
@TinyScripter that's absolutely incorrect. LocalScripts CANNOT function in the workspace.
You need to use player.PlayerGui:WaitForChild("ScreenGui") instead of player.PlayerGui.ScreenGui. That will help. If it doesn't, use FindFirstChild.
it's still not working... are you supposed to do player.PlayerGui:FindFirstChild("ScreenGui").Battery? i'm getting the error attempt to index a nil value
also, when i use waitforchild, i'm getting an infinite yield possible warning
Try player.StarterGui.ScreenGui.Battery?
please help im having same proplem im making a dj stand so when the dj clicks on the brick it should show a gui but it works perfectly in studio but not in game and i keep getting this error Screengui is not a valid member of playergui adn underneath it says workspace.DjstandBrick.script', Line 3 Stack end Please if anybody know whats wrong please reply