Hello. I was trying to create a game where the player tries to guess a word in a list with more parameters each time.
When I reached the second question, the changed text will only appear on the server, but not on the client.
Here is the code. (credit to @Imp_erator )
--ServerScriptService
local plrs = game:GetService("Players")
local question = game.Workspace.question
local plr = plrs.LocalPlayer
local a = game.StarterGui.ScreenGui.Game.A
local b = game.StarterGui.ScreenGui.Game.B
local chosenLetter = math.random(1,#letterBank)
wait(0.1)
print("why")
while true do
wait(1)
if question.Value == 2 then
print("i really hate this lol")
if chosenLetter == 1 then
print("hell")
a.Text = "...that starts with A, B or C"
b.Text = "...that has less than one million people"
end
if chosenLetter == 2 then
print("hell")
a.Text = "...that starts with D, F, G, I, K or L"
b.Text = "...that has less than one million people"
end
if chosenLetter == 3 then
print("hell")
a.Text = "...that starts with M, N or P"
b.Text = "...that has less than one million people"
end
if chosenLetter == 4 then
print("hell")
a.Text = "...that starts with S, T, U or V"
b.Text = "...that has less than 1,000,000 people"
end
if chosenLetter == 5 then
print("hell")
a.Text = "...that starts with A, D, L or M"
b.Text = "...that has less than 100,000 people"
end
if chosenLetter == 6 then
print("hell")
a.Text = "...that starts with N, P, S, T or V"
b.Text = "...that has less than 100,000 people"
end
if chosenLetter == 7 then
print("hell")
a.Text = "...that starts with A, B, C or D"
b.Text = "...that has more than 40,000,000 people"
end
if chosenLetter == 8 then
print("hell")
a.Text = "...that starts with E, F, G or H"
b.Text = "...that has more than 40,000,000 people"
end
wait(0.1)
if chosenLetter == 9 then
print("hell")
a.Text = "...that starts with I, J, K or L"
b.Text = "...that has more than 40,000,000 people"
end
--LocalScript in StarterGui
local rs = game:GetService("ReplicatedStorage")
local question = game.Workspace.question
script.Parent.FocusLost:Connect(function()
if question.Value == 1 then
script.Parent.Parent.A.Visible = true
rs.weDoingLetter:FireServer(script.Parent.Text)
end
if question.Value == 2 then
script.Parent.Parent.B.Visible = true
rs.weDoingPop:FireServer(script.Parent.Text)
end
if question.Value == 3 then
rs.weDoingSize:FireServer(script.Parent.Text)
end
end)
You’re changing instances in StarterGui, you need to change the GUI instances within the PlayerGui object for each respective client. The contents of StarterGui are copied into each player’s PlayerGui when they join (or die, depending on how your game is configured.) Changing the contents of StarterGui will not change existing instances within PlayerGui.
I’d like to add on to what @RBX_Lua said by stating that trying to index LocalPlayer in a server script returns a nil value - assuming this is passed through a RemoteEvent, you can index the first parameter of OnServerEvent to identify the player.
I think your first script is a LocalScript and should be in StarterPlayer.StarterPlayerScripts. I hope this helps
-- LocalScript in StarterPlayer.StarterPlayerScripts
local plrs = game:GetService("Players")
local question = workspace:WaitForChild("question")
local plr = plrs.LocalPlayer
local playerGui = plr:WaitForChild("PlayerGui")
local a = playerGui:WaitForChild("ScreenGui"):WaitForChild("Game"):WaitForChild("A")
local b = playerGui.ScreenGui.Game:WaitForChild("B")
local chosenLetter = math.random(1,#letterBank)
--wait(0.1)
print("why")
while true do
wait(1)
if question.Value == 2 then
print("i really hate this lol")
if chosenLetter == 1 then
print("hell")
a.Text = "...that starts with A, B or C"
b.Text = "...that has less than one million people"
end
if chosenLetter == 2 then
print("hell")
a.Text = "...that starts with D, F, G, I, K or L"
b.Text = "...that has less than one million people"
end
if chosenLetter == 3 then
print("hell")
a.Text = "...that starts with M, N or P"
b.Text = "...that has less than one million people"
end
if chosenLetter == 4 then
print("hell")
a.Text = "...that starts with S, T, U or V"
b.Text = "...that has less than 1,000,000 people"
end
if chosenLetter == 5 then
print("hell")
a.Text = "...that starts with A, D, L or M"
b.Text = "...that has less than 100,000 people"
end
if chosenLetter == 6 then
print("hell")
a.Text = "...that starts with N, P, S, T or V"
b.Text = "...that has less than 100,000 people"
end
if chosenLetter == 7 then
print("hell")
a.Text = "...that starts with A, B, C or D"
b.Text = "...that has more than 40,000,000 people"
end
if chosenLetter == 8 then
print("hell")
a.Text = "...that starts with E, F, G or H"
b.Text = "...that has more than 40,000,000 people"
end
--wait(0.1)
if chosenLetter == 9 then
print("hell")
a.Text = "...that starts with I, J, K or L"
b.Text = "...that has more than 40,000,000 people"
end
end
end
local rs = game:GetService("ReplicatedStorage")
local question = workspace:WaitForChild("question")
--LocalScript in StarterGui
script.Parent.FocusLost:Connect(function()
if question.Value == 1 then
script.Parent.Parent.A.Visible = true
rs:WaitForChild("weDoingLetter"):FireServer(script.Parent.Text)
end
if question.Value == 2 then
script.Parent.Parent.B.Visible = true
rs:WaitForChild("weDoingPop"):FireServer(script.Parent.Text)
end
if question.Value == 3 then
rs:WaitForChild("weDoingSize"):FireServer(script.Parent.Text)
end
end)