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

This Team Changing and Class choosing gui works in studio but not in Online mode?

local qingyun   = script.Parent.Frame.Qingyun
local tianying  = script.Parent.Frame.Tianying
local thousand  = script.Parent.Frame.Thousand
local longevity = script.Parent.Frame.Longevity
local fenxiang  = script.Parent.Frame.Fenxiang
local ghostking = script.Parent.Frame.Ghost

local Player = game.Players.LocalPlayer
local Leaderstat = Player.Stats.Faction
local Leaderstat = Player.Stats

function choose_faction(name)
	local Leaderstat = Player.Stats.Faction
	
	Leaderstat.Value = name
    Player.TeamColor = BrickColor.new("Cyan")
    Player:LoadCharacter()
	
	script.Parent:Destroy()
end

qingyun.MouseButton1Click:connect(function() choose_faction("Qing Yun") end)
tianying.MouseButton1Click:connect(function() choose_faction("Tian Ying") end)  
thousand.MouseButton1Click:connect(function() choose_faction("Thousand Poison") end)  
longevity.MouseButton1Click:connect(function() choose_faction("Longevity") end) 
fenxiang.MouseButton1Click:connect(function() choose_faction("Fen Xiang") end)  
ghostking.MouseButton1Click:connect(function() choose_faction("Ghost King") end)

This script goes with a GUI which are placed in ReplicatedStorage.

2 comments

0

You are using the same Variable name twice. local Leaderstat rename it.

0

Do not only post code, or only post an explanation. Both are required to make a good question.

1 answer

it better be a local script and because you said

local Player = game.Players.LocalPlayer

The Player won't load in the actual game... Try doing this...

local qingyun   = script.Parent.Frame.Qingyun
local tianying  = script.Parent.Frame.Tianying
local thousand  = script.Parent.Frame.Thousand
local longevity = script.Parent.Frame.Longevity
local fenxiang  = script.Parent.Frame.Fenxiang
local ghostking = script.Parent.Frame.Ghost
wait(1) -- added wait so it gives amount of time for the player to load
local Player = game:GetService("Players").LocalPlayer
local Leaderstat = Player.Stats.Faction
local Leaderstat = Player.Stats

function choose_faction(name)
    local Leaderstat = Player.Stats.Faction

    Leaderstat.Value = name
    Player.TeamColor = BrickColor.new("Cyan")
    Player:LoadCharacter()

    script.Parent:Destroy()
end

qingyun.MouseButton1Click:connect(function() choose_faction("Qing Yun") end)
tianying.MouseButton1Click:connect(function() choose_faction("Tian Ying") end)  
thousand.MouseButton1Click:connect(function() choose_faction("Thousand Poison") end)  
longevity.MouseButton1Click:connect(function() choose_faction("Longevity") end) 
fenxiang.MouseButton1Click:connect(function() choose_faction("Fen Xiang") end)  
ghostking.MouseButton1Click:connect(function() choose_faction("Ghost King") end)

if that won't work using PlayerAdded like this..

game:GetService("Players").PlayerAdded:connect(function(Player)
local qingyun   = script.Parent.Frame.Qingyun
local tianying  = script.Parent.Frame.Tianying
local thousand  = script.Parent.Frame.Thousand
local longevity = script.Parent.Frame.Longevity
local fenxiang  = script.Parent.Frame.Fenxiang
local ghostking = script.Parent.Frame.Ghost

local Leaderstat = Player.Stats.Faction
local Leaderstat = Player.Stats

function choose_faction(name)
    local Leaderstat = Player.Stats.Faction

    Leaderstat.Value = name
    Player.TeamColor = BrickColor.new("Cyan")
    Player:LoadCharacter()

    script.Parent:Destroy()
end

qingyun.MouseButton1Click:connect(function() choose_faction("Qing Yun") end)
tianying.MouseButton1Click:connect(function() choose_faction("Tian Ying") end)  
thousand.MouseButton1Click:connect(function() choose_faction("Thousand Poison") end)  
longevity.MouseButton1Click:connect(function() choose_faction("Longevity") end) 
fenxiang.MouseButton1Click:connect(function() choose_faction("Fen Xiang") end)  
ghostking.MouseButton1Click:connect(function() choose_faction("Ghost King") end)
end)

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