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

Tool not being saved after death problem?

I have a shop gui where you can buy weapons and gears and im trying to make it so that when a player has enough currency called Gems, they can purchase a weapon and it would go inside the player's Backpack and StarterGear. The problem that i am having is that after the weapon goes inside the player's Backpack and StarterGear and then i reset or leave the game, the weapon doesn't stay in my inventory. I have gear dev products in my game and those save in my inventory when i purchase them.

It could be that when i purchase the weapon, it's in a Local Script and i have Filtering Enabled on. But if it is, that's the problem i am having and i'm not that great with Remote Events/Functions.

This is the code in a Local Script, inside StarterGui

local player = game.Players.LocalPlayer
local gems = player:WaitForChild('leaderstats').Gems
local buyButton = script.Parent
local equipButton = script.Parent.Equip
local errorMessage = script.Parent.Parent.Parent.Parent.Parent.ErrorMessage
local gemImage = script.Parent.Gem

script.Parent.MouseButton1Click:connect(function()
	if gems.Value >= 50 and not player.Backpack:FindFirstChild('HyperlaserGun') and not player.StarterGear:FindFirstChild('HyperlaserGun') and not player.Character:FindFirstChild('HyperlaserGun') then
		game.Lighting.WeaponFolder.HyperlaserGun:Clone().Parent = player.Backpack
		game.Lighting.WeaponFolder.HyperlaserGun:Clone().Parent = player.StarterGear
		gems.Value = gems.Value - 50
		equipButton.Visible = true
		gemImage.Visible = false
	else
		if player.Backpack:FindFirstChild('HyperlaserGun') or player.StarterGear:FindFirstChild('HyperlaserGun') or player.Character:FindFirstChild('HyperlaserGun') then
			errorMessage.Visible = true
			errorMessage.Text = 'You already own this item!'
			wait(1.5)
			errorMessage.Visible = false
			errorMessage.Text = "You don't have enough Gems to purchase this!"
		else	
		errorMessage.Visible = true
		wait(1.5)
		errorMessage.Visible = false			
			
		end
	end
end)

1 answer

✓ Accepted answer

Instead of a mousebutton1click event, wrap this in an on server event and the player variable will be the first parameter.

-- Basic setup for the remote event. Must be in a Server Script.

RemoteEvent.OnServerEvent:Connect(function(player, amt)
    if player.leaderstats.Gems.Value >= amt then
        -- Handle the purchase here. How it's cloned into the player.
    end
end)

Now the localscript bit.

script.Parent.MouseButton1Click:Connect(function()
    -- Handle the errors inside of this Local Script. Like the TextLabels and stuff changing text when they have < 50 gems. Not from the server.
end)

Remember this is the basic setup. I can't give you the code just like that, this is a help site not request. :)

good luck

1 comment

0

I already figured out how to make this FE compatable, but that works too!

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