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

Can this be changed?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

Hello, I am working on this click regen that gives you a tool once you click. Now would there be anyway to make it where you keep the item after death?

local itemname = "Flashlight"   




local item = game.Lighting:findFirstChild(tostring(itemname))
local trigger = script.Parent

enabled = true

function onClick(plyr)

    if plyr.Backpack:findFirstChild(tostring(itemname)) == nil and enabled == true then

        enabled = false

        trigger.BrickColor = BrickColor.new("Black")

        local itemclone = item:clone()
        itemclone.Parent = plyr.Backpack

        wait(2)

        enabled = true
        trigger.BrickColor = BrickColor.new("Black")

    end
end

script.Parent.ClickDetector.MouseClick:connect(onClick)

2 answers

Log in to vote
-1
Answered by 9 years ago

Instead of backpack clone the item to Startergear and it will stay with them forever.

Ad
Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

If you clone 'item' into the player's StarterGear as well, then they will respawn with the item still in their inventory.

local itemname = "Flashlight"   
local item = game.Lighting:findFirstChild(itemname)
local trigger = script.Parent
local enabled = true

function onClick(plyr)
    if plyr.Backpack:FindFirstChild(itemname) == nil and enabled then
        enabled = false
        trigger.BrickColor = BrickColor.new("Black")
        item:Clone().Parent = plyr.Backpack
        item:Clone().Parent = plyr.StarterGear --Clone to startergear
        wait(2)
        enabled = true
        trigger.BrickColor = BrickColor.new("Black")
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClick)

Answer this question