Hey! I am making a pizzeria simulator game and i have a problem, This script doesn’t work, i don’t know why because it don’t have any red lines in Roblox Studio.
This script used to work like this: There is random number that means what customer is coming and what pizza is needed. Then if the pizza isn’t made in 30 seconds, The Customer is going away and the next one is coming (next random number) Anyways here is the script:
repeat
local Customer = math.random(1,3)
if Customer == 1 then
workspace.RedHuman.Transparency = 0
game.StarterGui.ScreenGui.List.Text = “Peperoni”
wait(30)
else if Customer == 2 then
workspace.BlueHuman.Transparency = 0
game.StarterGui.ScreenGui.List.Text = “Cheese”
wait(30)
else if Customer == 3 then
workspace.GreenHuman.Transparency = 0
game.StarterGui.ScreenGui.List.Text = “Nothing”
wait(30)
end
end
end
until Customer == 4
Anyone can please help?
Remove the space between else
and if
oh, ok i will try to. But when i scripted things like that i did it with space and it worked.
A few things, again, remove the spaes between else
and if
, also why are you using a repeat until loop with a continue that’s never going to be met? You’re better off using a while true do loop.
Use this
while true do
local Customer = math.random(1,3)
if Customer == 1 then
workspace.RedHuman.Transparency = 0
game.StarterGui.ScreenGui.List.Text = "Peperoni"
elseif Customer == 2 then
workspace.BlueHuman.Transparency = 0
game.StarterGui.ScreenGui.List.Text = "Cheese"
else
workspace.GreenHuman.Transparency = 0
game.StarterGui.ScreenGui.List.Text = "Nothing"
end
wait(30)
end
It does what you want but is more polished. You were also putting wait(30)
in every condition when you could just do it at the end. It was error cause the ends were put incorrect for your else if
s, it’s much more preferred to do it like this.
Also why are you referencing StarterGui? That’s nothing to do anything until a respawn, you have to reference the Gui in PlayerGui. Where is this script located?
It is in workspace, and the script still doesn’t work.
Which bit doesn’t work? The text setting or jsut all of it?
All of it, i join the game and nothing happens.
What type of script is it? Regular Script or LocalScript? If it’s regular, then it’s probably not doing anything since you’re setting the transparency for all those to 0, which is completely visible, and setting the text from StarterGui, Trying adding a print in that loop to confirm it’s actually doing something
It is a local script. (The post must be 30 letters so idk what to write here lol)
There’s your issue, local scripts do not work in workspace, put it in StarterPlayerScripts, and reference the Gui from PlayerGui, not StarterGui
1 Like
It will not work in the workspace since having local scripts in the workspace means no local player is defined.
1 Like
OK! (The post must be 30 letters so idk what to write here lol)
If you need help with converting the code to use PlayerGui than StarterGui, I can help with that, it’s probably going to not be taht difficult though
Old - game.StarterGui.ScreenGui.List.Text
New - game.Players.LocalPlayer.PlayerGui.ScreenGui.List.Text
Well, it works but the text isn’t changing.
Use this then
local player = game.Players.LocalPlayer
local gui = player:WaitForChild("PlayerGui")
while true do
local Customer = math.random(1,3)
if Customer == 1 then
workspace.RedHuman.Transparency = 0
gui.ScreenGui.List.Text = "Peperoni"
elseif Customer == 2 then
workspace.BlueHuman.Transparency = 0
gui.ScreenGui.List.Text = "Cheese"
else
workspace.GreenHuman.Transparency = 0
gui.ScreenGui.List.Text = "Nothing"
end
wait(30)
end
Basically what @IEnforce_Lawz but a bit cleaner since you’re already removing a lot of repetition, you can even make it less repeitive by changing the gui varaible to local gui = player:WaitForChild("PlayerGui").ScreenGui.List
and changing the code around
Yeah it work but the text isn’t changing yet, if it’s annoing you can stop replying.
Isn’t changing yet? Are you getting any errors?
No errors (red lines) and in the downe left corner there is no errors too
Maybe this?
local player = game.Players.LocalPlayer
local gui = player.PlayerGui.ScreenGui.List
while true do
local Customer = math.random(1,3)
if Customer == 1 then
workspace.RedHuman.Transparency = 0
gui.Text = "Peperoni"
elseif Customer == 2 then
workspace.BlueHuman.Transparency = 0
gui.Text = "Cheese"
else
workspace.GreenHuman.Transparency = 0
gui.Text = "Nothing"
end
wait(30)
end