Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
EpicLilC 150
8 years ago

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)

0
Have you defined 'gui' earlier in the code? TheDeadlyPanther 2460 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

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)

Ad

Answer this question