Search code examples
robloxluau

I am making a AutoItem script for Roblox and it is not giving me the item on join and reset like it's supposed to


My script is supposed to give me Items when I join and reset but it is not working, the script is hooked up to teams. I tried to change it to a LocalScript and a ServerScript but that did not work. I was expecting the script to give me items when I join and reset my character.

I have tried to change the way I give the player items too, but nothing I tried so far does anything that makes the script work, I have also checked Roblox Dev Console.

Here is my script.

local Owner = game.Teams["Group Owner"]
local Dev = game.Teams["Developer"]
local SR = game.Teams["SR's[Super Rank's]"]
local SHR = game.Teams["SHR's"]
local HR = game.Teams["HR'S"]
local MR = game.Teams["MR's"]
local LR = game.Teams["LR's[Normal Cafe Staff]"]

game.Players.PlayerAdded:Connect(function(player)
    -- Admin Tools
    -- Admin Tools
    if player.Team == Owner then
        -- Gives High Rank Tools
        local Admin = game.ServerStorage["Admin Card"]
        local Fob = game.ServerStorage["Paxton Access Fob"]
        local Key = game.ServerStorage["Shutter Key"]
        local Remote = game.ServerStorage["Firewall Shutter Remote"]

        local AdminClone = Admin:Clone()
        local FobClone = Fob:Clone()
        local KeyClone = Key:Clone()
        local RemoteClone = Remote:Clone()

        AdminClone.Parent = player.Backpack
        FobClone.Parent = player.Backpack
        KeyClone.Parent = player.Backpack
        RemoteClone.Parent = player.Backpack
    end
    if player.Team == Dev then
        -- Gives High Rank Tools
        local Admin = game.ServerStorage["Admin Card"]
        local Fob = game.ServerStorage["Paxton Access Fob"]
        local Key = game.ServerStorage["Shutter Key"]
        local Remote = game.ServerStorage["Firewall Shutter Remote"]

        local AdminClone = Admin:Clone()
        local FobClone = Fob:Clone()
        local KeyClone = Key:Clone()
        local RemoteClone = Remote:Clone()

        AdminClone.Parent = player.Backpack
        FobClone.Parent = player.Backpack
        KeyClone.Parent = player.Backpack
        RemoteClone.Parent = player.Backpack
    end
    if player.Team == SR then
        -- Gives High Rank Tools
        local Admin = game.ServerStorage["Admin Card"]
        local Fob = game.ServerStorage["Paxton Access Fob"]
        local Key = game.ServerStorage["Shutter Key"]
        local Remote = game.ServerStorage["Firewall Shutter Remote"]

        local AdminClone = Admin:Clone()
        local FobClone = Fob:Clone()
        local KeyClone = Key:Clone()
        local RemoteClone = Remote:Clone()

        AdminClone.Parent = player.Backpack
        FobClone.Parent = player.Backpack
        KeyClone.Parent = player.Backpack
        RemoteClone.Parent = player.Backpack
    end
    if player.Team == SHR then
        -- Gives High Rank Tools
        local Admin = game.ServerStorage["Admin Card"]
        local Fob = game.ServerStorage["Paxton Access Fob"]
        local Key = game.ServerStorage["Shutter Key"]
        local Remote = game.ServerStorage["Firewall Shutter Remote"]

        local AdminClone = Admin:Clone()
        local FobClone = Fob:Clone()
        local KeyClone = Key:Clone()
        local RemoteClone = Remote:Clone()

        AdminClone.Parent = player.Backpack
        FobClone.Parent = player.Backpack
        KeyClone.Parent = player.Backpack
        RemoteClone.Parent = player.Backpack
    end

    -- Normal Tools
    if player.Team == HR then
        -- Gives LR Tools
        local Card = game.ServerStorage.Card
        Card.Parent = player.Backpack
    end
    if player.Team == MR then
        -- Gives LR Tools
        local Card = game.ServerStorage.Card
        Card.Parent = player.Backpack
    end
    if player.Team == LR then
        -- Gives LR Tools
        local Card = game.ServerStorage.Card
        Card.Parent = player.Backpack
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    -- Admin Tools
    if player.Team == Owner then
        -- Gives High Rank Tools
        local Admin = game.ServerStorage["Admin Card"]
        local Fob = game.ServerStorage["Paxton Access Fob"]
        local Key = game.ServerStorage["Shutter Key"]
        local Remote = game.ServerStorage["Firewall Shutter Remote"]

        local AdminClone = Admin:Clone()
        local FobClone = Fob:Clone()
        local KeyClone = Key:Clone()
        local RemoteClone = Remote:Clone()

        AdminClone.Parent = player.Backpack
        FobClone.Parent = player.Backpack
        KeyClone.Parent = player.Backpack
        RemoteClone.Parent = player.Backpack
    end
    if player.Team == Dev then
        -- Gives High Rank Tools
        local Admin = game.ServerStorage["Admin Card"]
        local Fob = game.ServerStorage["Paxton Access Fob"]
        local Key = game.ServerStorage["Shutter Key"]
        local Remote = game.ServerStorage["Firewall Shutter Remote"]

        local AdminClone = Admin:Clone()
        local FobClone = Fob:Clone()
        local KeyClone = Key:Clone()
        local RemoteClone = Remote:Clone()

        AdminClone.Parent = player.Backpack
        FobClone.Parent = player.Backpack
        KeyClone.Parent = player.Backpack
        RemoteClone.Parent = player.Backpack
    end
    if player.Team == SR then
        -- Gives High Rank Tools
        local Admin = game.ServerStorage["Admin Card"]
        local Fob = game.ServerStorage["Paxton Access Fob"]
        local Key = game.ServerStorage["Shutter Key"]
        local Remote = game.ServerStorage["Firewall Shutter Remote"]

        local AdminClone = Admin:Clone()
        local FobClone = Fob:Clone()
        local KeyClone = Key:Clone()
        local RemoteClone = Remote:Clone()

        AdminClone.Parent = player.Backpack
        FobClone.Parent = player.Backpack
        KeyClone.Parent = player.Backpack
        RemoteClone.Parent = player.Backpack
    end
    if player.Team == SHR then
        -- Gives High Rank Tools
        local Admin = game.ServerStorage["Admin Card"]
        local Fob = game.ServerStorage["Paxton Access Fob"]
        local Key = game.ServerStorage["Shutter Key"]
        local Remote = game.ServerStorage["Firewall Shutter Remote"]
        
        local AdminClone = Admin:Clone()
        local FobClone = Fob:Clone()
        local KeyClone = Key:Clone()
        local RemoteClone = Remote:Clone()
        
        AdminClone.Parent = player.Backpack
        FobClone.Parent = player.Backpack
        KeyClone.Parent = player.Backpack
        RemoteClone.Parent = player.Backpack
    end
    
    -- Normal Tools
    if player.Team == HR then
        -- Gives LR Tools
        local Card = game.ServerStorage.Card
        Card.Parent = player.Backpack
    end
    if player.Team == MR then
        -- Gives LR Tools
        local Card = game.ServerStorage.Card
        Card.Parent = player.Backpack
    end
    if player.Team == LR then
        -- Gives LR Tools
        local Card = game.ServerStorage.Card
        Card.Parent = player.Backpack
    end
end)

Solution

  • Your issue may be that you are giving players tools only when they join the game the first time. You may want to use the Player.CharacterAdded signal so that they are given tools every time their character model is added to the Workspace, this includes after they respawn.

    local ServerStorage = game:GetService ("ServerStorage")
    local Teams = game:GetService("Teams")
    
    -- define which teams get which tools
    local highRankTools = {
        ServerStorage["Admin Card"],
        ServerStorage["Paxton Access Fob"],
        ServerStorage["Shutter Key"],
        ServerStorage["Firewall Shutter Remote"],
    },
    local normalRankTools = {
        ServerStorage["Card"],
    }
    local tools = {
        ["Group Owner"] = highRankTools,
        ["Developer"] = highRankTools,
        ["SR's[Super Rank's]"] = highRankTools,
        ["SHR's"] = highRankTools,
        ["HR'S"] = normalRankTools,
        ["MR's"] = normalRankTools,
        ["LR's[Normal Cafe Staff]"] = normalRankTools,
    }
    
    game.Players.PlayerAdded:Connect(function(player)
        player.CharacterAdded:Connect(function(character)
            -- check if there are any tools for the player
            local teamTools = tools[player.Team.Name]
            if teamTools then
                -- give all the tools to the player
                for _, tool in ipairs(teamTools) do
                    local clone = tool:Clone()
                    clone.Parent = player.Backpack
                end
            else
                print(string.format("No tools available for %s's team, %s", player.Name, player.Team.Name))
            end
        end)
    end)