How i make a player everytime spawn with a tool after buying it on a shop

I have a shop that i want when you buy the item everytime you respawn you get the item, any ideas of how doing it?

3 Likes

Either use datastore so it saves across servers and then use .CharacterAdded or StarterPack to add the tool to the player when they join.

1 Like

You need to connect an event when the Player joins the game, then another connect another event for when the character spawns (within the first event):

local Players = game:GetService("Players")

local function onCharacterAdded(player)
	local character = player.Character
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		local lastTool = player.LastTool.Value -- This is a Value added to the Player that I retrieve in the data load
		humanoid:EquipTool(lastTool)
	end
end

local function playerAdded(player)
	-- You would load you data here for Tools bought and last Tool equipped
	-- I tend to write the equipped Tool data to Values under the Player
	-- Save & Load of the Data needs to be handled using DataStore or ProfileService or some such
-- THE CHARACTER JOINED CONNECT - THIS REPEATS ON RESPAWN
	player.CharacterAdded:Connect(function()
		onCharacterAdded(player)
	end)
end

-- THE PLAYER JOINED CONNECT
Players.PlayerAdded:Connect(function(player)
	playerAdded(player)
end)

I use ProfileService for data storage to store what items the player has bought and what the last Tool equipped was:

I used these 2 vids to figure out how to implement ProfileService:

1 Like