UI script not running

To be honest your code is quite confusing, in your place I’d rewrite it without seemingly unnecessary stuff like defining a function which you are gonna call once, enclosing its conents in task.spawn??, etc

1 Like

the issue was that ur script tried to use scriptSelectedTeamValue but that object didnt exist so when it reached scriptSelectedTeamValue = Team it crashed silently inside taskspawn and stopped the rest of the buttons from loading or working

u gotta make sure there’s an ObjectValue named SelectedTeam inside the script before calling LoadTeams or else it just breaks without saying anything in output

U should add this before LoadTeams

if not script:FindFirstChild("SelectedTeam") then
	local val = Instance.new("ObjectValue")
	val.Name = "SelectedTeam"
	val.Parent = script
end
1 Like

is the button’s code a local script?

task.spawn shouldnt hide errors, thats what pcall does, and even then it doesnt halt the rest of the script

2 Likes

@LocalKarura

Yes it’s a LocalScript

@oplkel

It’s an ObjectValue

@ForeverSp4rK

It does already exist

Is there anything else that could have caused this? Maybe some sort of setting? This script used to work, but stopped all of a sudden. Not sure what change caused it

Yeah, the task.spawn part was just me messing around trying to find the issue. But the reason I put it into a function is so that later on I can script possibly a loading screen and other “refresh” functions if the player unlocks more teams while in-game

Wait the script is client side?

1 Like

Hey can u use debug like print(1) in the load team function and down and check where is stop printing

In the for loop ur looping through the game ur waitforchild instead use GetService

Ensure team button have child bool value have name Choosen and interactable

Ensure that the paths are correct like main.smth.smth

1 Like
print "1"

local Player = game:GetService("Players").LocalPlayer

script.Parent.Parent = Player:WaitForChild("PlayerGui")

local Menu = script.Parent.Frame
local TweenService = game:GetService("TweenService")

print "2 - variables loaded"

local function LoadTeams()
	print "3 - LoadTeams called"

	for _, Team in pairs(game:GetService("Teams"):GetChildren()) do -- For each team...
		print(Team.Name)
		-- Create button
		local Button = script.TeamButton:Clone()
		Button.Name = Team.Name
		Button.Text = Team.Name:upper()
		Button.LayoutOrder = Team.LayoutOrder.Value

		-- Determine if it's available
		local Available = false
		if Team:FindFirstChild("GroupID") then
			if Player:IsInGroup(Team.GroupID.Value) then
				Available = true
			elseif Player:GetRankInGroup(9898752) >= 100 then
				--Available = true
			else
				Available = false
			end
		elseif Team == game.Teams["Basic Training"] then
			if Player:GetRankInGroup(9898752) == Team.MinRank.Value then
				Available = true
			else
				Available = false
			end
		elseif Team:FindFirstChild("MinRank") then
			if Player:GetRankInGroup(9898752) >= Team.MinRank.Value then
				Available = true
			else
				Available = false
			end
		else
			Available = true
		end

		-- Create default team if the player doesn't choose before clicking Deploy
		if Team ~= game.Teams["USSF Personnel"] and Team ~= game.Teams["Civilian"] then
			if Available and not script.SelectedTeam.Value then
				script.SelectedTeam.Value = Team
			end
		end

		-- Set the click-ability of the button
		if Available then
			Button.Interactable = true
			Button.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
			Button.TextColor3 = Color3.fromRGB(255, 255, 255)
			Button.MouseEnter:Connect(function ()
				if not Button.Chosen.Value then
					game.TweenService:Create(Button, TweenInfo.new(0.1), {BackgroundColor3 = Color3.fromRGB(48, 48, 48)}):Play()
				end
			end)
			Button.MouseMoved:Connect(function ()
				if Button.BackgroundColor3 ~= Color3.fromRGB(48, 48, 48) and not Button.Chosen.Value then
					game.TweenService:Create(Button, TweenInfo.new(0.1), {BackgroundColor3 = Color3.fromRGB(48, 48, 48)}):Play()
				end
			end)
			Button.MouseLeave:Connect(function ()
				if not Button.Chosen.Value then
					game.TweenService:Create(Button, TweenInfo.new(0.1), {BackgroundColor3 = Color3.fromRGB(40, 40, 40)}):Play()
				end
			end)
			Button.MouseButton1Click:Connect(function ()
				if not Button.Interactable then return end
				for _, _Button in pairs(Menu.Main.TeamSelect:GetChildren()) do
					if _Button:IsA("TextButton") and _Button.Chosen.Value then
						_Button.Chosen.Value = false
						game.TweenService:Create(_Button, TweenInfo.new(0.1), {BackgroundColor3 = Color3.fromRGB(40, 40, 40)}):Play()
						game.TweenService:Create(_Button.UIPadding, TweenInfo.new(0.1), {PaddingTop = UDim.new(0.25, 0), PaddingBottom = UDim.new(0.25, 0)}):Play()
					end
				end
				Button.Chosen.Value = not Button.Chosen.Value
				if Button.Chosen.Value then
					game.TweenService:Create(Button, TweenInfo.new(0.1), {BackgroundColor3 = Color3.fromRGB(55, 55, 55)}):Play()
					game.TweenService:Create(Button.UIPadding, TweenInfo.new(0.1), {PaddingTop = UDim.new(0.225, 0), PaddingBottom = UDim.new(0.225, 0)}):Play()
				else
					game.TweenService:Create(Button.UIPadding, TweenInfo.new(0.1), {PaddingTop = UDim.new(0.25, 0), PaddingBottom = UDim.new(0.25, 0)}):Play()
				end
				script.SelectedTeam.Value = game.Teams[Button.Name]
			end)
		else
			Button.Interactable = false
			Button.BackgroundColor3 = Color3.fromRGB(20, 20, 20)
			Button.TextColor3 = Color3.fromRGB(130, 130, 130)
		end

		Button.Parent = Menu.Main.TeamSelect
	end
	print "3B - LoadTeams finished"
end

Menu.Main.Buttons.Deploy.MouseEnter:Connect(function ()
	print "4 - MouseEnter DeployBtn"
	TweenService:Create(Menu.Main.Buttons.Deploy, TweenInfo.new(0.1), {Size = UDim2.new(0.8, -2, 0.15, -2), BackgroundColor3 = Color3.fromRGB(255, 255, 255), TextColor3 = Color3.fromRGB(10, 10, 10)}):Play()
end)

Menu.Main.Buttons.Deploy.MouseLeave:Connect(function ()
	print "5 - MouseLeave DeployBtn"
	TweenService:Create(Menu.Main.Buttons.Deploy, TweenInfo.new(0.1), {Size = UDim2.new(0.8, 0, 0.15, 0), BackgroundColor3 = Color3.fromRGB(10, 10, 10), TextColor3 = Color3.fromRGB(220, 220, 220)}):Play()
end)

Menu.Main.Buttons.Deploy.MouseButton1Click:Connect(function ()
	print "6 - MouseButton1Click DeployBtn"
	if not Player.Character or Player.Character.Humanoid.Health <= 0 or Player.Team ~= script.SelectedTeam.Value then
		game.ReplicatedStorage.Deploy:FireServer(script.SelectedTeam.Value)
	end
	local Tween1 = TweenService:Create(script.Parent.Overlay, TweenInfo.new(0.5), {BackgroundTransparency = 0})
	Tween1:Play()
	Tween1.Completed:Wait()
	Menu.Visible = false
	local Tween2 = TweenService:Create(script.Parent.Overlay, TweenInfo.new(0.5), {BackgroundTransparency = 1})
	Tween2:Play()
	Tween2.Completed:Wait()
	script.Parent.Enabled = false
end)

game.ReplicatedStorage:WaitForChild("Died").OnClientEvent:Connect(function ()
	print "6 - DiedEvent"
	script.Parent.Enabled = true
	script.Parent.Overlay.BackgroundTransparency = 1
	Menu.Visible = false
	local Tween1 = TweenService:Create(script.Parent.Overlay, TweenInfo.new(5), {BackgroundTransparency = 0})
	Tween1:Play()
	Tween1.Completed:Wait()
	game.ReplicatedStorage.LoadCharacter:FireServer()
	local Tween2 = TweenService:Create(script.Parent.Overlay, TweenInfo.new(0.5), {BackgroundTransparency = 1})
	Tween2:Play()
	Tween2.Completed:Wait()
	script.Parent.Enabled = false
	Menu.Visible = true
end)

LoadTeams()
print "7 - Finished"

All of these are good, just double checked

Ok try

game.ReplicatedStorage.Deploy.OnServerEvent:Connect(function(player, selectedTeam)
    player.Team = selectedTeam
end)

Given that people still haven’t been able to assist successfully, you may want to consider sending a .rbxm file (Roblox Model File) containing just the script and the relevent UI. If the .rbxm file still doesn’t work in isolation, then it will allow people to test a bunch of different ideas rapidly.

1 Like

Ye good one too if it’s didn’t work send the file so we can test till we find what is the problem

gui.rbxl (76.2 KB)

From messing around with explorer, it seems that you have the Shop frame visible, rather than the Main frame. If you switch which of the 2 is visible, I believe it may fix your issue

2 Likes

There’s no way I didn’t notice that lol, was probably trying to make the shop gui then forgot about it lol, thank you so much

This is Note But it’s important for your code

image
image
image

Use it once as variable because it causes pressure on HTTPS
It’s better for you and make it less bugs HTTPS is the most annoying thing.

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.