Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
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.

0
You are using the same Variable name twice. local Leaderstat rename it. Pap3rLP 6 — 6y
0
Do not only post code, or only post an explanation. Both are required to make a good question. hiimgoodpack 2009 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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)
Ad

Answer this question