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

Why doesn't this work in online mode?

Asked by 8 years ago

This is my script.

 local Gui = script.Parent.ShopGui:clone()

function onTouched(hit)
    local human = hit.Parent:findFirstChild("Humanoid")
    local life = human.Parent.Name
    if (human ~= nil ) then
local Gui = script.Parent.ShopGui:clone()
Gui.Parent = game.Players.LocalPlayer.PlayerGui
    end
end
script.Parent.Touched:connect(onTouched)

In test mode, it works fine. But in online mode, the gui doesn't appear.

0
Is it in a local script? aquathorn321 858 — 8y
0
No, it is not in a local script. mustardfoot 90 — 8y
0
You can't get LocalPlayer from players in a local script outside of studio aquathorn321 858 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

On line 8 you are using "game.Players.LocalPlayer" If this script is not a local script then that can not be used. You could just find the player

 local Gui = script.Parent.ShopGui:clone()

function onTouched(hit)
    local human = hit.Parent:findFirstChild("Humanoid")
    local life = human.Parent.Name
    if (human ~= nil ) then
local Gui = script.Parent.ShopGui:clone()
Gui.Parent = game.Players:FindFirstChild(Life):WaitForChild("PlayerGui")
    end
end
script.Parent.Touched:connect(onTouched)

Ad

Answer this question