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

How to make screengui enable through this short script?

Asked by 6 years ago
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?

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 Krolaer 6 — 6y
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" Krolaer 6 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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
0
Seems very logical, I'll try it out right now Krolaer 6 — 6y
0
Thank you, man, it WORKS! Krolaer 6 — 6y
0
You're very welcome. Have a good day. :) MarceloFBentley 13 — 6y
Ad

Answer this question