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

How do i make this script only allow player to get one item and on death remove item?

Asked by 5 years ago

This script is currently allowing the player to spam more then one item in there inventory which can be used for abuse.

It also allows the player to keep the item when they die and respawn, how do i make this script were it only allows the player to get one item and when they die they loose the item? Thanks for helping!

you=script.Parent.Parent.Parent.Parent.Parent
script.Parent.Text=tostring(script.Parent.ItemName.Value)..": "..tonumber(script.Parent.Cost.Value).." "..tostring(script.Parent.Currency.Value)
script.Parent.MouseButton1Click:connect(function()
if you:findFirstChild("leaderstats") then
if you.leaderstats[script.Parent.Currency.Value].Value>=tonumber(script.Parent.Cost.Value) then
game.Lighting[script.Parent.ItemName.Value]:Clone().Parent=you.Backpack
game.Lighting[script.Parent.ItemName.Value]:Clone().Parent=you.StarterGear
script.Parent.Selected=false
wait(2)
script.Parent.Selected=true
end
end
end)
0
What is "you" defined as? Also, you shouldn't use Lighting as storage. User#19524 175 — 5y
0
You is basically player, Carforlife1 59 — 5y
0
And why are you getting you via 500 script.Parents? User#19524 175 — 5y
0
im guessing because there is more them one item buttons in a frame so i have to put parents. when i put Localplayer the script breaks. Carforlife1 59 — 5y

1 answer

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

You'd only clone the item in 'Backpack'. Cloning them into StarterGear will let them have the item again, as much as how many times it was cloned into backpack. Character dies, they lose everything in backpack. Character respawned, everything in StarterGear will be copied into backpack.

you=script.Parent.Parent.Parent.Parent.Parent
script.Parent.Text=tostring(script.Parent.ItemName.Value)..": "..tonumber(script.Parent.Cost.Value).." "..tostring(script.Parent.Currency.Value)
script.Parent.MouseButton1Click:connect(function()
if you:findFirstChild("leaderstats") then
if you.leaderstats[script.Parent.Currency.Value].Value>=tonumber(script.Parent.Cost.Value) then
game.Lighting[script.Parent.ItemName.Value]:Clone().Parent=you.Backpack
--StarterGear removed
script.Parent.Selected=false
wait(2)
script.Parent.Selected=true
end
end
end)

0
There we go that was the problem, i really didnt know starterGear and backpack were not the same now i know thanks again for your help this worked! Carforlife1 59 — 5y
Ad

Answer this question