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

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

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?

2 comments

0

Code block your code by clicking that blue lua button and pasting the script inside of the ~ lines.

0

Fixed, thanks.

1 answer

✓ Accepted answer

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.

2 comments

0

Oh wow, thanks! You're a big help, now I can continue working on my game! =)

0

remember to accept the answer lol

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