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

How to make screengui enable through this short script?

while true do
for i,plr in ipairs(game.Players:GetChildren()) do
		local char=plr.Character
		print("works")
		if char~=nil then
			local t=char:FindFirstChild("Torso")
			local h=char:FindFirstChild("Humanoid")
			if t~=nil and h~=nil then
				if h.Health>0 then
				 	pos1=t.Position*Vector3.new(1,0,1)
					pos2=script.Parent.Base.Position*Vector3.new(1,0,1)
					if (pos1-pos2).magnitude<10 then
						print((pos1-pos2).magnitude)
						print("I'm close enough")
						game.StarterGui.ScreenGui.Enabled=true
						print("Screengui should be enabled")
					else
						print("I'm not close enough")
						game.StarterGui.ScreenGui.Enabled=false
						end
					end
				end
			end
	end
wait(1)
end

What this script does is checks your distance every second, if the distance is less than 10, a screen gui should enable, but it doesen't - any idea why?

2 comments

0

I've tried enabling the screen gui with a script which only had the "game.StarterGui.ScreenGui.Enabled = true" row and it enables right away

0

The print command "I'm close enough" and "Screengui should be enabled" works on the output, but not the "game.StarterGui.ScreenGui.Enabled=true"

1 answer

✓ Accepted answer

Try enabling the Gui through the Player's PlayerGui? If you need me to elaborate more I'd happily connect with you.

If this doesn't solve the issue, I'll properly debug the issue. (I haven't tested the script; but have had past experiences with problems occurring like this.)

plr.PlayerGui:WaitForChild("ScreenGui").Enabled = true -- true / false

3 comments

0

Seems very logical, I'll try it out right now

0

Thank you, man, it WORKS!

0

You're very welcome. Have a good day. :)

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