Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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)
0
Tis is the magic of using gamepasses. DeceptiveCaster 3761 — 5y
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. ABK2017 406 — 5y
0
holy jesus a chicken can indent better then you LoganboyInCO 150 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

0
Thanks so much!!! It worked and helped me out a lot, thanks again! ChefDevRBLX 90 — 5y
0
well one more thing the text still changes back to Buy Sword after i die tho ChefDevRBLX 90 — 5y
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. Dev_Unreal 136 — 5y
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? ChefDevRBLX 90 — 5y
Ad

Answer this question