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

This script works in Studio, but not in Online Mode, how would I fix it?

Asked by 8 years ago
function onTouched (part)
 local h = part.Parent:findFirstChild("Humanoid")
local gui = game.Players.LocalPlayer.PlayerGui.ScreenGui
 if h~= nil then
    gui.BG.Visible = true
    gui.No.Visible = true
    gui.Question.Visible = true
    gui.Yes.Visible = true
    script.Parent.Transparency = 0
  end
end


script.Parent.Touched:connect(onTouched)

((Basically this script opens up 3 guis when the brick the script is in is touched))

Ideas? Comments?

0
Code block your code by clicking that blue lua button and pasting the script inside of the ~ lines. alphawolvess 1784 — 8y
0
Fixed, thanks. iBlessinq 15 — 8y

1 answer

Log in to vote
2
Answered by
pwnd64 106
8 years ago

LocalPlayer can only be accessed by localscripts. This is looking for the local player but there is none because it can't access it.

Try getting the player from the humanoid using :GetPlayerFromCharacter

function onTouched (part)

 local Humanoid = part.Parent:findFirstChild("Humanoid")

     if Humanoid ~= nil then

        local Gui = game.Players:GetPlayerFromCharacter(Humanoid.Parent)

        Gui.BG.Visible = true

        Gui.No.Visible = true

        Gui.Question.Visible = true

        Gui.Yes.Visible = true

        script.Parent.Transparency = 0

      end

end


script.Parent.Touched:connect(onTouched)

This will get the player from the parent of the humanoid. Tell me if there's any problems.

0
Oh wow, thanks! You're a big help, now I can continue working on my game! =) iBlessinq 15 — 8y
0
remember to accept the answer lol pwnd64 106 — 8y
Ad

Answer this question