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

Team is picked,screen goes black and doesn't change the team.Why is that?

Asked by 6 years ago

So, I cut out most of the script, but for some reason the script won't change the Player's team nor will it respawn the player.. Why?

local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
character = player.CharacterAdded:wait()
end
local gui = script.Parent:WaitForChild("IntroductionGui")
local menuMusic = gui:WaitForChild("MenuMusic")
local background = gui:WaitForChild("Background")
local logo = gui:WaitForChild("Logo")
local textFrame = gui:WaitForChild("Text")
local textOne = textFrame:WaitForChild("TextLabel1")
local textTwo = textFrame:WaitForChild("TextLabel2")
local ethicsCommitteeButton = gui:WaitForChild("EthicsCommitteeButton")
local dClassButton = gui:WaitForChild("DClassButton")
local intelligenceAgencyButton = gui:WaitForChild("IntelligenceAgencyButton")
local sciencetificDepartmentButton = gui:WaitForChild("ScientificDepartmentButton")
local foundationPersonnelButton = gui:WaitForChild("FoundationPersonnelButton")
local securityDepartmentButton = gui:WaitForChild("SecurityDepartmentButton")
local administrativeDepartmentButton = gui:WaitForChild("AdministrativeDepartmentButton")
local mobileTaskForceButton = gui:WaitForChild("MobileTaskForceButton")
local medicalDepartmentButton = gui:WaitForChild("MedicalDepartmentButton")
local chaosInsurgencyButton = gui:WaitForChild("ChaosInsurgencyButton")
local versionFrame = gui:WaitForChild("Version")
local errorNotificationFrame = gui:WaitForChild("ErrorNotification")
local errorText = errorNotificationFrame:WaitForChild("ErrorText")
local raidValue = game.Lighting:WaitForChild("RaidAuthorised")
local replicatedStorage = game:GetService("ReplicatedStorage")
local remote = replicatedStorage:WaitForChild("RemoteEventPlayerIntroductionManager")
--Data saving.
local chosen = false
if tostring(game.Players.LocalPlayer.Team) == "Pending" and player.Name ~= "Player1" then
    dClassButton.TextButton2.MouseButton1Click:connect(function()
        if chosen == false then
            if character then
                chosen = true
                gui.GroupGranted:Play()
                loadCharacterTransition()
                remote:FireServer("ChangeTeam", player, "D Class Personnel")
                remote:FireServer("LoadPlayer", player)
                if character:FindFirstChild("ForceField") then
                    character["ForceField"]:Destroy()
                end
            end
        end
    end)
    --- END OF SAME BUTTON
    intelligenceAgencyButton.TextButton.MouseButton1Click:connect(function()
        if player:IsInGroup(3131922) then
            if chosen == false then
                if character then
                    chosen = true
                    gui.GroupGranted:Play()
                    loadCharacterTransition()
                    remote:FireServer("ChangeTeam", player, "Intelligence Agency")
                    remote:FireServer("LoadPlayer", player)
                    if character:FindFirstChild("ForceField") then
                        character["ForceField"]:Destroy()
                    end
                end
            end
        else

1 answer

Log in to vote
0
Answered by 6 years ago

Don’t put events inside of if statements like you did on line 32. This is a RemoteEvent inside of ReplicatedStorage. Also, don’t use deprecated code. RBXScriptSignal:connect() is deprecated, switch to RBXScriptSignal:Connect() instead.

--Server Script
local teamChange = game:GetService("ReplicatedStorage").TeamChange

teamChange.OnServerEvent:Connect(function(plr, team)
    if not plr.Team or plr.Team ~= team then
        plr.Team = team
        plr.TeamColor = team.TeamColor

        plr:LoadCharacter()
        game.Workspace[plr.Name]:FindFirstChild("ForceField"):Destroy()
    end
end)

Now the local-script

local teamChange = game:GetService("ReplicatedStorage").TeamChange

script.Parent.MouseButton1Click:Connect(function()
    teamChange:FireServer(game:GetService("Teams").Team) --team here 
end)
0
In which line was the deprecated code in? OreoPatton 8 — 6y
Ad

Answer this question