yaeh this will probably work idk how it wouldnt
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.
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.
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
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.
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?
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.
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.
Can you please give me the updated script for the script i should have in the localscript
Your LocalScript is fine, it’s the Script inside the head that needs updating.
I’ve explained how to update your Script here: Cant make my text invisible with a script - #16 by SiebeYolo
I added this to my regular script in my model but its not working lines of code:
Server script (“Script”): sending Event
Client script (“LocalScript”): receiving Event
Could you add what you meant to my script that i already have? thank you
I quickly outlined what purpose each of your two scripts had. Your Script inside the Head needs to send the RemoteEvent, your LocalScript needs to receive the RemoteEvent.
You need to update your Script inside the Head to properly fire your RemoteEvent, instead of changing the StarterGui, which does not do anything regardless.
Im really confused can you give me the updates script and where i need to put it? im so sorry please help me with this one
hey, can u send me the full script?
-- 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 ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.SetRedLightGreenLight
local function rotatePart(part)
-- Store the original CFrame
local originalCFrame = part.CFrame
Event:FireAllClients()
-- 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
I’ve just replaced the line that used to be the StarterGui line, but there’s multiple issues with your code.
Ok so now that i used that exact script it didnt work, the green text doesnt become invisible, did i have to add a Localscript too? And what did i have to write there i literally forgot im sorry.
I’ll compile everything we’ve did so far in this thread.
- You need two scripts: your Script inside the Head model (which we’ll call Script for now!) and your LocalScript inside your ScreenGui (your LocalScript)
- The problem was that you were trying to change your UI through your Script and through the StarterGui, which is incorrect. We need to use a RemoteEvent to let every player connected to your game (Clients) know to change the UI.
Script:
-- 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 ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.SetRedLightGreenLight
local function rotatePart(part)
-- Store the original CFrame
local originalCFrame = part.CFrame
Event:FireAllClients()
-- 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
LocalScript
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)
Now, these scripts are very basic, so they’ll only disable your Green Light text once. In order to make it work better, you’ll have to use different parameters. If you need help with that, let me know.