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

Team change does work in studio but not in player?

Asked by 5 years ago

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.

0
Please edit that to make all of the script in the same format. I'm having a hard time reading it. Jexpler 63 — 5y
0
might be because you never used WaitForChild(event) on the client. theking48989987 2147 — 5y
0
might be because you never used WaitForChild(event) on the client. theking48989987 2147 — 5y
0
it cannot be localscript OOF greatneil80 2647 — 5y

1 answer

Log in to vote
0
Answered by
popeeyy 493 Moderation Voter
5 years ago

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.

0
Okay,but which mainframe? The script or what? When i put it in i get a script error. TheBrightDeveloper -5 — 5y
Ad

Answer this question