So, everything is fine and I get the tool but when I die I lose the tool, please help.
SCRIPT:
local player = game.Players.LocalPlayer local rs = game:GetService("ReplicatedStorage") local tool = rs:WaitForChild("Sword") local stats = player:WaitForChild("leaderstats") local button = script.Parent cost = 100 script.Parent.MouseButton1Click:Connect(function() if stats.Cash.Value >= cost then button.Text = 'ItemOwned' stats.Cash.Value = stats.Cash.Value - cost local clone = tool:Clone() clone.Parent = player.Backpack local clone2 = tool:Clone() clone2.Parent = player.StarterGear else button.Text = 'Need More Cash!' wait(1) button.Text = 'Buy Sword - $100' end end)
In filtering enabled, this will never work, no matter how hard you try to develop the client/local side of it.
Make a script, and RemoteEvent, and just below this line
script.Parent.MouseButton``1``Click:Connect(``function``()
Index to your event, as an example.
game.ReplicatedStorage.Event:FireServer(100)
Then, head over to your server script, and put this down
local tool = game.ReplicatedStorage:FindFirstChild("Sword") game.ReplicatedStorage.Event.OnServerEvent:Connect(function(player,cost) local stats = player:FindFirstChild("leaderstats") if stats.Cash.Value >= cost then Stats.Cash.Value = Stats.Cash.Value - cost local clone = tool:Clone() clone.Parent = player.Backpack local clone2 = tool:Clone() clone.Parent = player.StarterGear end end)
A tip is to always put everything that your player needs to see but no one elses in the client, otherwise, put it in the server, if the server doesn't recognize it, when the player dies it will NOT carry your tool over because the server doesn't know you should have it when you respawn.
This setup I gave you is not my ideal set up, but I won't go into explaining that set up as it can get quite advanced when it comes to Filtering Enabled, so I just wanted to go over the concept.