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

How to not lose gear when you LoadCharacter?

If someone buys something from this shop, they will get their item, but if you respawn, they lose their gear and also you can't buy 2 of the same item and I don't know the fix. This is the script for when you press the button to buy it.

script.Parent.MouseButton1Click:Connect(function()
	local plr = game.Players.LocalPlayer
	local Points = plr.leaderstats.Points
	if Points.Value >= 500 then
		local Event = game.ReplicatedStorage.Purchased
		Event:FireServer("GravityCoil", 500)
	end
end)

Also, here is another, so can someone help me with the gear being kept when respawned and maybe tell me how to make someone be able to buy more of the same item.?

local CountName = "Points"

game.Players.PlayerAdded:connect(function(Player)
	local leaderstats = Player:FindFirstChild('leaderstats') or Instance.new("Folder", Player)
	leaderstats.Name = "leaderstats"
	
	local Points = leaderstats:FindFirstChild(CountName) or Instance.new("IntValue", leaderstats)
	Points.Name = CountName
	Points.Value = 0
	
	Player.CharacterAdded:connect(function(Character)
		local d = true
		Character:WaitForChild("Humanoid").Died:connect(function()
			if (d) then
				d = false
				Points.Value = Points.Value + 100
				
				local CloneMe = game.StarterGui.Shop:Clone()
				CloneMe.Parent = Player.PlayerGui

			end
		end)
	end)
end)
-------------------- New Function
game.ReplicatedStorage.Purchased.OnServerEvent:Connect(function(plr,Message,Cost)
	local Item = game.ServerStorage:FindFirstChild(Message)
	local Points = plr.leaderstats.Points
	Points.Value = Points.Value - Cost
	Item:Clone()
	Item.Parent = plr.Backpack
end)

2 comments

0

Is there a starter pack for individual players? I think you can add an item to a players starter pack and then when they re-spawn they will have it but i'm not completely sure

0

also does this give any errors?

1 answer

Hello, Ca_rsonB!

Try this:

local CountName = "Points"

local ItemBuyers = {} --This will save the name of the players that buy(will just give em the item, add anyone you want)

game.Players.PlayerAdded:connect(function(Player)
    local leaderstats = Player:FindFirstChild('leaderstats') or Instance.new("Folder", Player)
    leaderstats.Name = "leaderstats"

    local Points = leaderstats:FindFirstChild(CountName) or Instance.new("IntValue", leaderstats)
    Points.Name = CountName
    Points.Value = 0

    Player.CharacterAdded:connect(function(Character)
        local d = true
	for i,v in pairs(ItemBuyers) do
	    if v[1] == Player.UserId then --Tests if player purchased
	            local Item = game.ServerStorage:FindFirstChild(v[2]) --Gives item
		    Item:Clone()
    		    Item.Parent = Player.Backpack
            end 
	end
        Character:WaitForChild("Humanoid").Died:connect(function()
            if (d) then
                d = false
                Points.Value = Points.Value + 100

                local CloneMe = game.StarterGui.Shop:Clone()
                CloneMe.Parent = Player.PlayerGui

            end
        end)
    end)
end)
-------------------- New Function
game.ReplicatedStorage.Purchased.OnServerEvent:Connect(function(plr,Message,Cost)
    local Item = game.ServerStorage:FindFirstChild(Message)
    local Points = plr.leaderstats.Points
    Points.Value = Points.Value - Cost
    Item:Clone()
    Item.Parent = plr.Backpack
    table.insert(ItemBuyers, {plr.UserId, Message}) --Adds the player id and item to a table with the format: {USERID, ITEM}
end)

Good Luck with your games

2 comments

0

It doesn't seem to work.

0

Try now

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