Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why doesn't this nightvision script work in the game online?

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)

1 comment

0

Have you defined 'gui' earlier in the code?

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.