Cant make my text invisible with a script

This is my script that works perfectly fine, but the only thing that isnt working is that the text visibility isnt becoming false while the function is running:

    -- Wait 5 seconds after the game starts
    wait(5)

    -- Get the Head model
     local head = script.Parent

    -- TweenService for smooth animation
    local TweenService = game:GetService("TweenService")

    -- TweenInfo for reuse
    local tweenInfo = TweenInfo.new(1)

    local function rotatePart(part)

game.StarterGui.RedLightGreenLight.GreenLight.Visible = false
-- Store the original CFrame
local originalCFrame = part.CFrame

-- Create and play the tween to rotate 180 degrees
local goal = {CFrame = originalCFrame * CFrame.Angles(0, math.rad(180), 0)}
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()

-- Wait for the tween to complete
tween.Completed:Wait()

-- Wait 4 seconds
wait(4)

-- Create and play the tween to rotate back to the original position
local reverseGoal = {CFrame = originalCFrame}
local reverseTween = TweenService:Create(part, tweenInfo, reverseGoal)
reverseTween:Play()
    end

    -- Iterate through all the parts inside the Head model
    for _, part in pairs(head:GetChildren()) do
if part:IsA("BasePart") then
	rotatePart(part)
end
   end

// In my StarterGui i have a ScreenGUI called “RedLightGreenLight” and in that screen GUI i have 2 textLabels one is called “GreenLight”

4 Likes

do game.Players.LocalPlayer.RedLightGreenLight.GreenLight.Visible = false

changing it in startergui only does something when the gui resets i think

2 Likes

Didnt do anything even the rest of the script stops working now :confused:

1 Like

is this a localscript or server script

1 Like

Regular “Script” in one of my models, i also tried other things like using a local script in the text itself and other things but nothing works, I want the text to be invisible whenever the roation function is running

1 Like

oh okay then so add a remote event inside ReplicatedStorage
then put a localscriipt inside of the green light ui element that says

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
script.Parent.Visible = false
end)

then change the 1st line of server script to something like
game.ReplicatedStorage.RemoteEvent:FireAllClients() – assuming the model is the parent of script

and for the part where you want the text to be invisible whenever the rotation function is running, you could (probably) have another remote for making text visiible after server stops the rotation function

1 Like

thanks for triyng to help me but im extremely slow and i added a remote event in replicated storage and a local script in my text but after this im just confused, so thank u but if u know another idea on how to add it to the function in the script i wrote then ill be grateful

1 Like

Few things wrong with this, i’ll line them up.

  1. The GUI of players in stored inside the player object in a folder called PlayerGui. Referencing the StarterGui will not work
  2. Changing GUI’s is something you better do on the server. A better way of doing this is, like mentioned before, firing a Remote Event.

Say for example, you want to change the text visibility of your TextLabel called “RedLightGreenLight”. You have a RemoteEvent inside ReplicatedStorage called “SetRedLightGreenLight”

Server Script would look like this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.SetRedLightGreenLight

--All your code has happened, now it's time to change the Text to false, we do this by firing the event
Event:FireAllClients()

A LocalScript, inside your TextLabel, to receive your event that you sent on the server

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.SetRedLightGreenLight
local TextLabel = script.Parent

Event.OnClientEvent:Connect(function()
       TextLabel.Visible = false
end)
1 Like

yaeh this will probably work idk how it wouldnt

1 Like

I will do everything you told me to but before i do is this correct if my text label is in the “RedLightGreenLight” and not this one ? This one is a screenGui and in it s a text label called “GreenLight” this is how it looks: StarterGUI < RedLightGreenLight < GreenLight

I don’t know how your game is structured, but in my example it would look like this:

ReplicatedStorage
--SetRedLightGreenLight (RemoteEvent)
StarterGui
-- ScreenGui
-----RedLightGreenLight (TextLabel)
----------LocalScript

I hope it makes sense how I outlined everything.

Edit: As long as you are setting your variables to the correct position (so where your items are located), it should work fine.

2 Likes

So ill call the Remote event “SetRedLightGreenLight” ?
But under that you said that its a text label but its a screenGui that i called “RedLightGreenLight”

Just so its right so when i follow your steps its correct

You can call it whatever you want! Just make sure all your variables are properly referenced. If I understand correctly, your GUI looks like this:

RedLightGreenLight (ScreenGui)
-- GreenLight (TextLabel)
-- RedLight (TextLabel)

Now how I would do it, is just insert a LocalScript as child of your ScreenGui, so it looks like this:

RedLightGreenLight (ScreenGui)
-- GreenLight (TextLabel)
-- RedLight (TextLabel)
-- LocalScript

Then, you set up your variables again, like this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.SetRedLightGreenLight
local ScreenGui = script.Parent
local GreenLight = ScreenGui.GreenLight
local RedLight = ScreenGui.RedLight

Then, you’ll receive the event, and make the GreenLight TextLabel invisible like this:

Event.OnClientEvent:Connect(function()
   GreenLight.Visible = false
end)

Now, if you want to do different things with the same event, look into setting different parameters.

Edit: in this example the SetRedLightGreenLight RemoteEvent only makes your GreenLight invisible! To make it visible again, or toggle the visibility of your RedLight TextLabel, you’re going to have to expand on the code.

1 Like

Ok so this is how my LocalScript looks in my screen gui:

*** local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local Event = ReplicatedStorage.SetRedLightGreenLight
local ScreenGui = script.Parent
local GreenLight = ScreenGui.GreenLight
local RedLight = ScreenGui.RedLight

Event.OnClientEvent:Connect(function()
GreenLight.Visible = false
*** end)

But it didnt make the green text invisible so it didnt work, And this is how my script in my doll model looks:

-- Wait 5 seconds after the game starts
wait(5)

-- Get the Head model
local head = script.Parent

-- TweenService for smooth animation
local TweenService = game:GetService("TweenService")

-- TweenInfo for reuse
local tweenInfo = TweenInfo.new(1)

local function rotatePart(part)

game.StarterGui.RedLightGreenLight.GreenLight.Visible = false

-- Store the original CFrame
local originalCFrame = part.CFrame

-- Create and play the tween to rotate 180 degrees
local goal = {CFrame = originalCFrame * CFrame.Angles(0, math.rad(180), 0)}
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()

-- Wait for the tween to complete
tween.Completed:Wait()

-- Wait 4 seconds
wait(4)

-- Create and play the tween to rotate back to the original position
local reverseGoal = {CFrame = originalCFrame}
local reverseTween = TweenService:Create(part, tweenInfo, reverseGoal)
reverseTween:Play()
end

-- Iterate through all the parts inside the Head model
for _, part in pairs(head:GetChildren()) do
if part:IsA("BasePart") then
	rotatePart(part)
end
end
1 Like

It’s not working because you’re never sending the event, you’re only receiving it.

We’ve established before that this line of code doesn’t do anything, so you have to remove and replace it.

game.StarterGui.RedLightGreenLight.GreenLight.Visible = false

You have to fire your event to all clients, so you have to define what your event is and then fire it.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.SetRedLightGreenLight

Add this code to the top of your script, where you define all your variables. Next, replace the StarterGui line with firing your event, like this:

Event:FireAllClients()

It seems your issues are due to a lack of understanding the basics, so I advise you learn those and then get into more difficult stuff.

2 Likes

Oh okay yeah i dont usually get into advanced stuff i have more experience with otherthings but ur helping me out so much if this works, So these lines of script that you just wrote ill put this in the LocalScript in my GUI right?

2 Likes

No, my previous answer is about your server script, in this case the script inside the Head.

Server script (“Script”): sending Event
Client script (“LocalScript”): receiving Event

I feel like you’re not completely understanding why we’re using a RemoteEvent.

1 Like

Nope i have no idea how they work , Ok so ill copy this that u just sent me these 2 lines of code and put it in my regular script in my model yeah? Do i replace the line that i wrote on my own in that script?

Yes. RemoteEvents are very easy to use and understand though. Basically, they’re used to interact between the server and the client. The Server is your game basically. Everything you do on the server replicates to all the players. The clients are your players connected to your game. UI for example, exists on the client. To communicate between the Server and the Client, you can use RemoteEvents.

Also important: whenever a player connects to your game, everything inside StarterGui gets cloned into a folder inside the Player object called “PlayerGui”. Editing your StarterGui while your game is running does not do anything, because all the UI you see while playing comes from the PlayerGui folder.

2 Likes

Can you please give me the updated script for the script i should have in the localscript