I have a tool and a script that clones the tool from serverstorage to the player backpack and startergear when you purchase it so that way it doesnt go away after a player resets but the scripts work at first but then after resetting they no longer work.
Server script:
game.ReplicatedStorage.PurchaseBucket.OnServerEvent:Connect(function(player,amount)
player.leaderstats.Shells.Value= player.leaderstats.Shells.Value - 50
game.ServerStorage.Bucket:Clone().Parent = player.Backpack
game.ServerStorage.Bucket:Clone().Parent = player.StarterGear
end)
Purchase script inside GUI button:
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if player.leaderstats.Shells.Value >= 50 then
-- Checks if player has enough shells
game.Workspace.PurchaseSuccessful:Play()
game.ReplicatedStorage.PurchaseBucket:FireServer(0)
-- Fires RemoteEvent that charges player
script.Parent.Text = ("Purchased")
script.Disabled = true
else
game.Workspace.PurchaseFailed:Play()
script.Parent.Text = ("Insufficient funds!")
wait(3)
script.Parent.Text = ("Purchase for 50 Shells...")
end
end)
Script inside tool:
local player = script:FindFirstAncestorWhichIsA("Player") or game:GetService("Players"):GetPlayerFromCharacter(script.Parent.Parent)
local character = player.Character or player.CharacterAdded:Wait()
local Animator = character:WaitForChild("Humanoid"):WaitForChild("Animator")
local tool = script.Parent
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://7378586179"
local loaded = Animator:LoadAnimation(animation)
local GUI = player.PlayerGui
tool.Activated:Connect(function()
loaded:Play()
GUI.BucketGui.Enabled = true
tool.Sand.Transparency = 0
end)
local GUI = player.PlayerGui
script.Parent.Unequipped:Connect(function()
GUI.BucketGui.Enabled = false
end)
game.ReplicatedStorage.EmptyBucket.OnServerEvent:Connect(function()
script.Parent.Sand.Transparency = 1
end)