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”
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
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
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
The GUI of players in stored inside the player object in a folder called PlayerGui. Referencing the StarterGui will not work
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)
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
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
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:
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
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
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?
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.