Issue with guis

So I’ve done a system with help so when you step on a block it makes a ui appear it only does it once how do I make it go on infinite amount of times?

their is a shutdown button to close all the ui so it don’t show again here is the code of the shutdown button:

local players = game:GetService(“Players”)
local player = players.LocalPlayer
local playerGui = player:WaitForChild(“PlayerGui”)

local button = script.Parent

button.MouseButton1Click:Connect(function()
for _, screenGui in ipairs(playerGui:GetChildren()) do
if screenGui:IsA(“ScreenGui”) then
screenGui.Enabled = false
end
end
end)

1 Like

Firstly: A tip for displaying code is writing “```” before and after you code to format it properly.

Secondly, I can’t say for sure what the issue is. I see no issues with the provided code. Could you show the code for displaying the UI? The code for you block.

The issue might be one of the following:

  • Button changes it locally, while block (might) change it server-side.
  • Button hides it in a different way than the block displays it
    [Not likely]

thx for the tip and ye i can send 1 that makes 1 of them visible its a complex system…

but here.

game.ReplicatedStorage.ShowGUI.OnClientEvent:Connect(function() script.Parent.ChatICON.Visible = not script.Parent.ChatICON.Visible end)” thats like it with all of them but with different names.

Probably could just do something like this, the Touched function returns back the HitPart of some sort of BasePart so you could probably check for which player exactly touched it by using the HitPart.Parent (Which is actually the Character), call GetPlayerFromCharacter() via the Players Service, and make the UI visible whenever you need to:

local Plrs = game:GetService("Players")
local Plr = Plrs.LocalPlayer
local PlrGui = Plr:WaitForChild("PlayerGui")

local Button = script.Parent
local Block = -- Block Part here
local UIObject = -- The path where you want the UI to be

local function Touched(Hit) -- Hit returns back a Part
    local TouchedPlr = Plrs:GetPlayerFromCharacter(Hit.Parent) --Hit.Parent is the Hit's Parent (Or Character Model)

    if TouchedPlr and TouchedPlr == Plr then -- Check if it's equal to the LocalPlayer
        UIObject.Visible = true -- Make the UI Visible
    end
end

Button.MouseButton1Click:Connect(function()
    for _, Gui in pairs(PlrGui:GetChildren()) do
        if Gui:IsA("ScreenGui") then
            Gui.Enabled = false
        end
    end
end)

Block.Touched:Connect(Touched)

System does work but you can no longer exit the gui after

Is the script a child of the button you’re pressing? The script Jackscarlett made should work fine, it’s just a matter of putting it in the right place!

i dont think it is

eeeeee

Here it is the workstuff folder is the opening the ui

You’d probably have to implement some Magnitude check so that you’re able to access the Frame from a close enough distance, while at far away distances the UI will disappear

Using Touched Events would only activate upon via Physics of a certain object (And no we do not talk about TouchEnded cause that is a menace), hence why we have our workarounds to go about them:

local TargetDistance = 10

for _, Plr in pairs(game.Players:GetPlayers()) do
    local Char = Plr.Character
    local Torso = Char:WaitForChild("Torso")
    local Magnitude = (Torso.Position - Block.Position).Magnitude

    if Magnitude < TargetDistance then 
        UIObject.Visible = true
    else
        UIObject.Visible = false
    end
end

You could probably put this through a loop every 1-2 seconds or so and it’d work just fine I’d assume

Will this be in the block itself or in server script service that’s where my current one is[poll type=regular results=always chartType=bar]

I did a poll so you dont got to type

  • The block
  • Server script service

0 voters

Either one could work really, it’s just your preference on where you want it to go

Just make sure to handle it inside a loop so that it keeps repeating over and over to detect who’s close to the Block for the UI to be enabled

Should i of edited it for the names of the ui Im a bad scripter i am slowly learning at a slugs paste

local TargetDistance = 10

for _, Plr in pairs(game.Players:GetPlayers()) do
local Char = Plr.Character
local Torso = Char:WaitForChild(“Torso”)
local Magnitude = (Torso.Position - Block.Position).Magnitude

if Magnitude < TargetDistance then 
	Options.Visible = true
else
	Options.Visible = false
end

end

The code no longer sees the old one and the output says

Players.3DRobloxGameDev.PlayerGui.Options.Startup.TurnOff.LocalScript:9: Expected identifier when parsing expression, got ‘local’

What

local TargetDistance = 10
local Cooldown = 5

while true do
    for _, Plr in pairs(game.Players:GetPlayers()) do
        local Char = Plr.Character
        local Torso = Char:WaitForChild("Torso")
        local Magnitude = (Torso.Position - Block.Position).Magnitude

        if Magnitude < TargetDistance then 
            UIObject.Visible = true
        else
            UIObject.Visible = false
        end
    end

    task.wait(Cooldown)
end

Just put it inside a loop, aka a way for the Script to keep running the same specific stuff over and over again until it meets a certain condition

I would highly recommend searching the Developer API References before making your post here :thinking:

I thought a loop is like this:

While true do
-code stuff here-
end

Have you read this yet? This should answer all of your questions regarding loops.

I have read it a lot of times but I got a issue where I have to read it a lot for it to sink in

It’s fine, doesn’t always sick for me either.

Short version of the article:
There are different kinds of loops: For, While & Repeat.

-- Different kinds of loops:

-- While loop:
while <condition> do
	-- Checks if <condition> is true, THEN RUNS if its true.
	-- Code here
end

-- Repeat loop:
repeat
	-- Code here will be run, THEN CHECKS if <condition> is true. Repeats if true.
until <condition>

-- For loops:
for key, value in ipairs(<list>) do
	-- Key is the key of the value, value is the value. Example:
	-- { Name = "Tim", Age = "34" } would first give Key == "Name" and Value == "Tim"
	-- Code here
end

for <varName> = <startValue>, <endValue> do
	-- Increments variable varName from startValue to endValue by 1. Example:
	-- for i=1, 10 do print(i) end -- This would print "1", "2", "3" ... "10"
	-- Code here
end

for <varName> = <startValue>, <endValue>, <incrementBy> do
	-- Works same as previous for-loop, except you choose what it increments by.
	-- Setting <incrementBy> to 10 would increase the variable by 10 each loop.
	-- Code here
end

Thank you i will always keep this in mind when doing loops!

1 Like