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

How do I keep a tool when I die after I already bought it?

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)

3 comments

0

Tis is the magic of using gamepasses.

0

See if it’s actually getting parented to StarterGear, run a Print, I wouldn’t clone the tool again, I’d clone the clone but that’s just me.

0

holy jesus a chicken can indent better then you

1 answer

✓ Accepted answer

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.

4 comments

0

Thanks so much!!! It worked and helped me out a lot, thanks again!

0

well one more thing the text still changes back to Buy Sword after i die tho

0

I apologize for the late reply on that one. If you don't want it to reset, take your attention to, "ResetGuiOnSpawn," which is a property of a ScreenGui, it will not reset then and will keep the gui the exact same when you die, and after you respawn.

0

Ok i got it all but one more issue, sorry to bug but when i leave the text resets and lets me buy it again how can i fix this?

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