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

Why wont a startercharacter be added to the starter player and how would I be able to?

Asked by 2 years ago

I'm working on a game with different starter characters and I'm trying to give a player a starter character via a local script. I currently get no errors/warnings, but I don't know how I would be able to do this. Can somebody explain to me why It won't work and help me achieve what I'm attempting?

local ReplicatedStorage = game:GetService("ReplicatedStorage")

script.Parent.MouseButton1Down:Connect(function(Player)
    local TroopType = script.Parent.Parent.TroopType
    local Country = script.Parent.Parent.Country

    ---CountryUniforms
    local AlliedPowers = {
        --Officer
        ["AmericanOfficer"] = ReplicatedStorage.TeamStaterCharacters.AlliedPowers.Officer:FindFirstChild("AmericanOfficer"),
        ["FrenchOfficer"] = ReplicatedStorage.TeamStaterCharacters.AlliedPowers.Officer:FindFirstChild("FrenchOfficer"),
        ["BritishOfficer"] = ReplicatedStorage.TeamStaterCharacters.AlliedPowers.Officer:FindFirstChild("BritishOfficer"),
        --Soldier
        ["AmericanSoldier"] = ReplicatedStorage.TeamStaterCharacters.AlliedPowers.Soldier:FindFirstChild("AmericanSoldier"),
        ["FrenchSoldier"] = ReplicatedStorage.TeamStaterCharacters.AlliedPowers.Soldier:FindFirstChild("FrenchSoldier"),
        ["BritishSoldier"] = ReplicatedStorage.TeamStaterCharacters.AlliedPowers.Soldier:FindFirstChild("BritishSoldier"),
        --Sapper
        ["AmericanSapper"] = ReplicatedStorage.TeamStaterCharacters.AlliedPowers.Sapper:FindFirstChild("AmericanSapper"),
        ["FrenchSapper"] = ReplicatedStorage.TeamStaterCharacters.AlliedPowers.Sapper:FindFirstChild("FrenchSapper"),
        ["BritishSapper"] = ReplicatedStorage.TeamStaterCharacters.AlliedPowers.Sapper:FindFirstChild("BritishSapper")
    }
    local CentralPowers = {
        --Officer
        ["GermanOfficer"] = ReplicatedStorage.TeamStaterCharacters.CentralPowers.Officer:FindFirstChild("GermanOfficer"),
        ["AustrianOfficer"] = ReplicatedStorage.TeamStaterCharacters.CentralPowers.Officer:FindFirstChild("AustrianOfficer"),
        ["OttomanOfficer"] = ReplicatedStorage.TeamStaterCharacters.CentralPowers.Officer:FindFirstChild("OttomanOfficer"),
        --Soldier
        ["GermanSoldier"] = ReplicatedStorage.TeamStaterCharacters.CentralPowers.Soldier:FindFirstChild("GermanSoldier"),
        ["AustrianSoldier"] = ReplicatedStorage.TeamStaterCharacters.CentralPowers.Soldier:FindFirstChild("AustrianSoldier"),
        ["OttomanSoldier"] = ReplicatedStorage.TeamStaterCharacters.CentralPowers.Soldier:FindFirstChild("OttomanSoldier"),
        --Sapper
        ["GermanSapper"] = ReplicatedStorage.TeamStaterCharacters.CentralPowers.Soldier:FindFirstChild("GermanSapper"),
        ["AustrianSapper"] = ReplicatedStorage.TeamStaterCharacters.CentralPowers.Soldier:FindFirstChild("AustrianSapper"),
        ["OttomanSapper"] = ReplicatedStorage.TeamStaterCharacters.CentralPowers.Soldier:FindFirstChild("OttomanSapper")
    }

    if TroopType.Value ~= "" then
        if Country.Value == "French" then
            if TroopType.Value == "Soldier" then
                print("Soldier Uniform")
                local FrenchSoldierCharacter = AlliedPowers.FrenchSoldier:Clone()
                FrenchSoldierCharacter.Name = "StarterCharacter"
                FrenchSoldierCharacter.Parent = game.StarterPlayer
            elseif TroopType.Value == "Sapper" then
                print("Sapper Uniform")
                local FrenchSapperCharacter = AlliedPowers.FrenchSapper:Clone()
                FrenchSapperCharacter.Name = "StarterCharacter"
                FrenchSapperCharacter.Parent = game.StarterPlayer
            elseif TroopType.Value == "Officer" then
                print("Officer Uniform")
                local FrenchOfficerCharacter = AlliedPowers.FrenchOfficer:Clone()
                FrenchOfficerCharacter.Name = "StarterCharacter"
                FrenchOfficerCharacter.Parent = game.StarterPlayer
            elseif Country.Value == "American" then
                if TroopType.Value == "Soldier" then
                    print("Soldier Uniform")
                    local AmericanSoldierCharacter = AlliedPowers.AmericanSoldier:Clone()
                    AmericanSoldierCharacter.Name = "StarterCharacter"
                    AmericanSoldierCharacter.Parent = game.StarterPlayer
                elseif TroopType.Value == "Sapper" then
                    print("Sapper Uniform")
                    local AmericanSapperCharacter = AlliedPowers.AmericanSapper:Clone()
                    AmericanSapperCharacter.Name = "StarterCharacter"
                    AmericanSapperCharacter.Parent = game.StarterPlayer
                elseif TroopType.Value == "Officer" then
                    print("Officer Uniform")
                    local AmericanOfficerCharacter = AlliedPowers.AmericanOfficer:Clone()
                    AmericanOfficerCharacter.Name = "StarterCharacter"
                    AmericanOfficerCharacter.Parent = game.StarterPlayer
                end
            elseif Country.Value == "British" then
                if TroopType.Value == "Soldier" then
                    print("Soldier Uniform")
                    local BritishSoldierCharacter = AlliedPowers.BritishSoldier:Clone()
                    BritishSoldierCharacter.Name = "StarterCharacter"
                    BritishSoldierCharacter.Parent = game.StarterPlayer
                elseif TroopType.Value == "Sapper" then
                    print("Sapper Uniform")
                    local BritishOfficerCharacter = AlliedPowers.BritishSapper:Clone()
                    BritishOfficerCharacter.Parent = game.StarterPlayer
                elseif TroopType.Value == "Officer" then
                    print("Officer Uniform")
                    local BritishOfficerCharacter = AlliedPowers.BritishOfficer:Clone()
                    BritishOfficerCharacter.Name = "StarterCharacter"
                    BritishOfficerCharacter.Parent = game.StarterPlayer             
                end
            elseif Country.Value == "German" then
                if TroopType.Value == "Soldier" then
                    print("Soldier Uniform")
                    local GermanSoldierCharacter = CentralPowers.GermanSoldier:Clone()
                    GermanSoldierCharacter.Name = "StarterCharacter"
                    GermanSoldierCharacter.Parent = game.StarterPlayer
                elseif TroopType.Value == "Sapper" then
                    print("Sapper Uniform")
                    local GermanSapperCharacter = CentralPowers.GermanSapper:Clone()
                    GermanSapperCharacter.Name = "StarterCharacter"
                    GermanSapperCharacter.Parent = game.StarterPlayer
                elseif TroopType.Value == "Officer" then
                    print("Officer Uniform")
                    local GermanOfficerCharacter = CentralPowers.GermanOfficer:Clone()
                    GermanOfficerCharacter.Name = "StarterCharacter"
                    GermanOfficerCharacter.Parent = game.StarterPlayer
                end
            elseif Country.Value == "Astria-Hungary" then
                if TroopType.Value == "Soldier" then
                    print("Soldier Uniform")
                    local AustrianSoldierCharacter = CentralPowers.AustrianSoldier:Clone()
                    AustrianSoldierCharacter.Name = "StarterCharacter"
                    AustrianSoldierCharacter.Parent = game.StarterPlayer
                elseif TroopType.Value == "Sapper" then
                    print("Sapper Uniform")
                    local AustrianSapperCharacter = CentralPowers.AustrianSapper:Clone()
                    AustrianSapperCharacter.Name = "StarterCharacter"
                    AustrianSapperCharacter.Parent = game.StarterPlayer
                elseif TroopType.Value == "Officer" then
                    print("Officer Uniform")
                    local AustrianOfficerCharacter =CentralPowers. AustrianOfficer:Clone()
                    AustrianOfficerCharacter.Name = "StarterCharacter"
                    AustrianOfficerCharacter.Parent = game.StarterPlayer
                end
            elseif Country.Value == "Ottoman Empire" then
                if TroopType.Value == "Soldier" then
                    print("Soldier Uniform")
                    local OttomanSoldierCharacter = CentralPowers.OttomanSoldier:Clone()
                    OttomanSoldierCharacter.Name = "StarterCharacter"
                    OttomanSoldierCharacter.Parent = game.StarterPlayer
                elseif TroopType.Value == "Sapper" then
                    print("Sapper Uniform")
                    local OttomanSapperCharacter = CentralPowers.OttomanSapper:Clone()
                    OttomanSapperCharacter.Name = "StarterCharacter"
                    OttomanSapperCharacter.Parent = game.StarterPlayer
                elseif TroopType.Value == "Officer" then
                    print("Officer Uniform")
                    local OttomanOfficerCharacter = CentralPowers.OttomanOfficer:Clone()
                    OttomanOfficerCharacter.Name = "StarterCharacter"
                    OttomanOfficerCharacter.Parent = game.StarterPlayer
                end
            end
        end
    end
    ReplicatedStorage.Events.SpawnEvent:FireServer(Player)
end)

1 answer

Log in to vote
1
Answered by 2 years ago

First off, nice avatar.

Second, MouseButton1Down does not return the Player, it returns the pixels.

Third, StarterCharacter cannot work with the client(Can someone double check?)

To get the player(With a localscript, server scripts will return nil) is by doing this

local LocalPlayer=game:GetService("Players").LocalPlayer

There ya go.

Ad

Answer this question