Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

1 comment

0

any output? maybe a statement wasn't correct, so try separating them with print() s to know where it stopped

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.