Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Team change does work in studio but not in player?

So this is the whole script : ~~~~~~~~~~~~~~~~~


local Player = game.Players.LocalPlayer

for i,v in pairs(script.Parent.MainFrame.ScrollingFrame:GetChildren()) do
	if v:IsA("TextButton") then
		v.MouseButton1Click:Connect(function()
			if v:FindFirstChild("Group Settings") then
				if Player:GetRankInGroup(v["Group Settings"].GroupId.Value) < v["Group Settings"].MinRank.Value then
					return
				end
			end
			
			if game:FindFirstChild("Teams") == nil then
				ErrorMsg("ERROR: You haven't inserted any teams in your game.")
			elseif game.Teams:FindFirstChild(v.Text) == nil then
				ErrorMsg("ERROR: The text of the button must be the same as the team name.")
			else
				game.ReplicatedStorage.TeamChanger:FireServer(v.Text)
			end
		end)
	end
end


function ErrorMsg(Msg)
	local M = Instance.new("Message")
	M.Text = Msg
	M.Parent = game.Workspace
	game.Debris:AddItem(M, 5)
end



So this is the script far.There is one more script for this.

local TC = Instance.new("RemoteEvent")
TC.Name = "TeamChanger"
TC.Parent = game.ReplicatedStorage

TC.OnServerEvent:Connect(function(Player, TeamName)
	Player.Team = game.Teams[TeamName]
	Player:LoadCharacter()
end)

Now some of the script dont get in the Lua Block but i dont know what to do with it.




4 comments

0

Please edit that to make all of the script in the same format. I'm having a hard time reading it.

0

might be because you never used WaitForChild(event) on the client.

0

might be because you never used WaitForChild(event) on the client.

0

it cannot be localscript OOF

1 answer

I have just modified these scripts and it seems to work fine.

In a NORMAL SCRIPT in ServerScriptService put in this code:

local TC = Instance.new("RemoteEvent") 
TC.Name = "TeamChanger" 
TC.Parent = game:GetService('ReplicatedStorage') --In case it gets renamed or something

TC.OnServerEvent:Connect(function(Player, TeamName) 
	Player.Team = game.Teams[TeamName] 
	Player:LoadCharacter() 
end)

In a LOCAL SCRIPT in the Parent of MainFrame put this code in:

local Player = game.Players.LocalPlayer

for i,v in pairs(script.Parent.MainFrame.ScrollingFrame:GetChildren()) do 
	if v:IsA("TextButton") then 
		v.MouseButton1Click:Connect(function() 
			if v:FindFirstChild("Group Settings") then 
				if Player:GetRankInGroup(v["Group Settings"].GroupId.Value) < v["Group Settings"].MinRank.Value then 
					return 
				end
			end
        	if game:FindFirstChild("Teams") == nil then
            	ErrorMsg("ERROR: You haven't inserted any teams in your game.")
        	elseif game.Teams:FindFirstChild(v.Text) == nil then
            	ErrorMsg("ERROR: The text of the button must be the same as the team name.")
        	else
            	game.ReplicatedStorage:WaitForChild('TeamChanger'):FireServer(v.Text) --Waits for TeamChanger to be created.
        	end
		end)
	end
end
		
function ErrorMsg(Msg) 
	local M = Instance.new("Message") 
	M.Text = Msg 
	M.Parent = game.Workspace 
	game.Debris:AddItem(M, 5) 
end

I explained what I changed in the scripts and make sure you're using the correct class types and in the correct places.

Let me know if you encounter any other issues.

1 comment

0

Okay,but which mainframe? The script or what? When i put it in i get a script error.

This discussion is preserved as it was. New answers, comments, and votes are closed.