Why Does This Not Work

here is my script its for 4 teams for gamemodes but it doesn’t create the 2 teams as asked:

t4 = script.Parent
players = game:GetService(“Players”)
plr = players.PlayerAdded:Wait()
teams = game:GetService(“Teams”)

t4.MouseButton1Click:Connect(function()
local yellow = Instance.new(“Team”)
yellow.Parent = teams
yellow.Name = “Yellow”
wait()

local green = Instance.new("Team")
yellow.Parent = teams
yellow.Name = "Green"
wait()
t4.Parent.Parent.Enabled = false

end)

Hey, I assume your new to scripting so I will try to make this as explained and in-depth as possible so it is easy to understand and learn from.

Lets look at your code so far

t4 = script.Parent
players = game:GetService(“Players”)
plr = players.PlayerAdded:Wait()
teams = game:GetService(“Teams”)

t4.MouseButton1Click:Connect(function()
  local yellow = Instance.new(“Team”)
  yellow.Parent = teams
  yellow.Name = “Yellow”
  wait()
  
  local green = Instance.new("Team")
  yellow.Parent = teams
  yellow.Name = "Green"
  wait()
  t4.Parent.Parent.Enabled = false
end)

We can assume that t4 is a Button of some sort.

In lua, you must declare variables using the local syntax. You can see this in your code local yellow = .... We should use this on every variable in the script however.

local t4 = script.Parent
--Removed players and plr variable due to it being unused. Make sure that instead of using PlayerAdded:Wait you use PlayerAdded:Connect
local teams = game:GetService(“Teams”)

t4.MouseButton1Click:Connect(function()
  local yellow = Instance.new(“Team”)
  yellow.Parent = teams
  yellow.Name = “Yellow”
  wait()
  
  local green = Instance.new("Team")
  yellow.Parent = teams
  yellow.Name = "Green"
  wait()
  t4.Parent.Parent.Enabled = false
end)

So far, so good! Now lets move in to Networking in Roblox. For sake of simplicity, I won’t explain networking in this post, but I urge you to do some research (the Roblox Docs is a good place to start learning!)

--localscript, inside the image button
local t4 = script.Parent
--Removed players and plr variable due to it being unused. Make sure that instead of using PlayerAdded:Wait you use PlayerAdded:Connect
local teams = game:GetService(“Teams”)
local Remote = game.ReplicatedStorage.RemoteEvent -- You'd probably want a better name here

t4.MouseButton1Click:Connect(function()
  Remote:FireServer() --The `player` argument is passed automatically!
  t4.Parent.Parent.Enabled = false
end)
--Script, likely in ServerScriptService
local Remote = game.ReplicatedStorage.RemoteEvent

Remote.OnServerEvent:Connect(function(player)
  --You should probably add sanity checks here to prevent exploiters from making teams

  local yellow = Instance.new(“Team”)
  yellow.Parent = teams
  yellow.Name = “Yellow”

  task.wait() --wait standalone is deprecated, use task.wait instead!
  
  local green = Instance.new("Team")
  green.Parent = teams
  green.Name = "Green"
end

And with that, it should work! But your system would preferably have a lot more components, this is just a barebone example for learning sake. Hopefully this helped!

2 Likes

u kinda made it too tall but i understand where your going and no, i am not a new scripter but i am bad at finding errors

1 Like

but i appreciate you and thanks

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