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

How do I make this GUI give the player their items when they spawn?

Asked by 10 years ago

The purpose of the GUI is to allow the player to select a weapon they want and they spawn with that weapon, but I can't get it to work right.

The weapons are in the game's lighting.

How do I tweak it so the GUI gives the player their weapon whenever they spawn?

local function equip_tools(player)
    local weps = game.Lighting["Weapons"]
    local inventory = player:findFirstChild("wep_storage")
    if inventory then 
        local purchased_wep = weps[inventory.purchased.Value]
        local gp_wep = weps:findFirstChild(inventory.game_pass.Value) or nil
        if gp_wep ~= nil then 
            gp_wep:Clone().Parent = player.Backpack
        end
        purchased_wep:Clone().Parent = player.Backpack
    else
        if map["Tools"]:findFirstChild("LinkedSword") then 
            map["Tools"]["LinkedSword"]:Clone().Parent = player.Backpack
        else
            map["Tools"]["Sword"]:Clone().Parent = player.Backpack
        end
    end
end
0
any output? maybe a statement wasn't correct, so try separating them with print() s to know where it stopped Tesouro 407 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago
local player = game.Players.LocalPlayer

--give tools function

repeat wait() until player.Character --Just to make sure it doesn't glitch
equip_tools() --Since player was already defined there is no need to insert it as a parameter

player.CharacterAdded:connect(equip_tools)

Sorry if this doesn't work, I'm tired and a tad rusty recently. Try it out and give output if it doesn't work out!

Also if you can't use it as a local script you could do

game.Players.PlayerAdded:connect(function(player)
    --give tools function

    repeat wait() until player.Character
    equip_tools()

    player.CharacterAdded:connect(equip_tools)
end)

Try either of these out

Sidenote: The first one has to be a local script inside the StarterGui or StarterPack

Ad

Answer this question