So i'm trying to make a nightvision script. It works when I test the game, but doesn't work when I play the game online. How do I fix this?
script.Parent.Equipped:connect(function() gui = Instance.new("ScreenGui", game.Players.LocalPlayer.PlayerGui) local frame = Instance.new("Frame",gui) frame.Size = UDim2.new(0.999, 0,0.994, 0) frame.BackgroundColor3 = Color3.fromRGB(0, 212, 0) frame.BackgroundTransparency = .6 end) script.Parent.Unequipped:connect(function() gui:Destroy() end)
It works only in Studio because you did "game.Players.LocalPlayer" (at line 2) which only works in local scripts. To correct this, you can either keep the same script but put it in a local script, or either do the following change if you want to keep it in a server script:
script.Parent.Equipped:connect(function() wait() Player = game.Players:GetPlayerFromCharacter(script.Parent.Parent) if Player~=nil then gui = Instance.new("ScreenGui", Player.PlayerGui) local frame = Instance.new("Frame",gui) frame.Size = UDim2.new(0.999, 0,0.994, 0) frame.BackgroundColor3 = Color3.fromRGB(0, 212, 0) frame.BackgroundTransparency = .6 end end) script.Parent.Unequipped:connect(function() gui:Destroy() end)