Maybe you are just in the server side, this happen because you only run the game(and not pressing play) and so no player, so no local stuff, so no local script
Hm yeah, that hasn’t fired. I do have another script, which just detects when a button is pressed and sets a value.
local button = player.PlayerGui["MainMenu UI"].BackgroundFrame.TeamButtonFOUR
local player = game:GetService("Players").LocalPlayer
function buttonPressed ()
game.ReplicatedStorage["Team Value"]["Team Number"].Value = 4
print("4")
end
button.MouseButton1Click:Connect(buttonPressed)
Here is my whole script if this helps, it’s just a personal game i am making for me and friends haha.
Ignore if my coding method is inefficient, i am learning lol.
local player = game:GetService("Players").LocalPlayer
local plrJoined = player.PlayerAdded
-- Short Cuts
local mainMenuEnabled = player.PlayerGui["MainMenu UI"].Enabled
local roundConfigEnabled = player.PlayerGui["Round Config"].Enabled
local teamAmount = game.ReplicatedStorage["Team Value"]["Team Number"].Value
-- True / False Variables
local hasCompletedTeamPhase = false
-- Main Function Body
local function BeforeRoundSetUp()
print("hi")
while true do -- Loop until a team has been selected
task.wait(1) -- Stop game crashing on while loop
if teamAmount == 1 then
hasCompletedTeamPhase = true
mainMenuEnabled = false
roundConfigEnabled = true
elseif teamAmount == 2 then
hasCompletedTeamPhase = true
mainMenuEnabled = false
roundConfigEnabled = true
elseif teamAmount == 3 then
hasCompletedTeamPhase = true
mainMenuEnabled = false
roundConfigEnabled = true
elseif teamAmount == 4 then
hasCompletedTeamPhase = true
mainMenuEnabled = false
roundConfigEnabled = true
if hasCompletedTeamPhase == true then -- as soon as a team has been selected stop the loop
break -- end loop
end
end
end
end
print("Script should be working fine!")
BeforeRoundSetUp()
This could be why here, PlayerAdded is an Event provided by the Players Service, not the individual LocalPlayer as they’re 2 different things here
If you’d like to check when a Player has been added to the game, use the game.Players.PlayerAdded Event instead for that
Another potential error you might get, is that the PlayerGui may not properly load on time the moment the LocalPlayer gets added, so you’d want to call the WaitForChild() function to ensure that object is in there
Tidying up your script a bit, try this and see if it works or not:
local Plrs = game:GetService("Players")
local RepS = game:GetService("ReplicatedStorage")
local Plr = Plrs.LocalPlayer
local PlrGui = Plr:WaitForChild("PlayerGui")
-- Short Cuts
local mainMenuEnabled = PlrGui:WaitForChild("MainMenu UI").Enabled
local roundConfigEnabled = PlrGui:WaitForChild("Round Config").Enabled
local teamAmount = RepS:WaitForChild("Team Value"):WaitForChild("Team Number").Value
-- True / False Variables
local hasCompletedTeamPhase = false
-- Main Function Body
local function BeforeRoundSetUp()
print("hi")
while true do -- Loop until a team has been selected
task.wait(1) -- Stop game crashing on while loop
if teamAmount == 1 then
hasCompletedTeamPhase = true
mainMenuEnabled = false
roundConfigEnabled = true
elseif teamAmount == 2 then
hasCompletedTeamPhase = true
mainMenuEnabled = false
roundConfigEnabled = true
elseif teamAmount == 3 then
hasCompletedTeamPhase = true
mainMenuEnabled = false
roundConfigEnabled = true
elseif teamAmount == 4 then
hasCompletedTeamPhase = true
mainMenuEnabled = false
roundConfigEnabled = true
if hasCompletedTeamPhase == true then -- as soon as a team has been selected stop the loop
break -- end loop
end
end
end
end
print("Script should be working fine!")
BeforeRoundSetUp()
Thanks for all the detailed tips, this will be really helpful!
The script does in-fact work, the function ran and also the little print at the bottom ran. The only issue i am facing now is the first UI does not disappear when the buttons are clicked.
I tried to simply just disable the MainMenu and enable to Config UI but that does’t seem to work. Maybe it’s just another issue i have made?
This is because you’re saving a Value within your teamAmount variable and the same goes for your mainMenuEnabled & roundConfigEnabled variables, the reason being is because when you reference a property of an Instance using a variable, it gets saved until you re-change the variable to something else
Personally for me, instead of using a Loop I would use something called a Changed Event which are exclusively for only Value Instance
These things fire whenever a value of that said “Instance” changes, and it can help tidy out our script to make it look a bit neater & slightly reduce performance as well:
local Plrs = game:GetService("Players")
local RepS = game:GetService("ReplicatedStorage")
local Plr = Plrs.LocalPlayer
local PlrGui = Plr:WaitForChild("PlayerGui")
-- Short Cuts
local mainMenu = PlrGui:WaitForChild("MainMenu UI")
local roundConfig = PlrGui:WaitForChild("Round Config")
local teamAmount = RepS:WaitForChild("Team Value"):WaitForChild("Team Number")
-- True / False Variables
local hasCompletedTeamPhase = false
-- Main Function Body
local function CheckTeam(NewValue)
if NewValue == 1 or NewValue == 2 or NewValue == 3 or NewValue == 4 then
hasCompletedTeamPhase = true
mainMenu.Enabled = false
roundConfig.Enabled = true
end
end
CheckTeam(teamAmount.Value) -- In case you want to fire it the moment you join, you can use this
teamAmount.Changed:Connect(CheckTeam) -- This will change the MOMENT a Player's Team changes and will check if it's 1-4,
I modified this script, so hopefully everything should work out just fine and if it doesn’t feel free to debug it with print() statements