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

Why won't this work??

wait(2) 

gpid = 188000708 -- Gamepass ID

local player = script.Parent.Parent
local GPS = game:GetService("GamePassService")

while true do
wait()
if player.Character.Humanoid.Health == 0 then
	if GPS:PlayerHasPass(player, gpid) then
		backup = player.Backpack:clone()
		backup.Parent = player.StarterGear
		end
	end
end

The script is meant to keep the players backpack if they have a certain gamepass. I tested it in studio and it did not work, then I tested it in a roblox game and it also didn't work, please could someone help/explain why it doesn't work?

The script is in a normal script and in the players backpack, and yes I do own the gamepass that I am using in the script.

1 answer

✓ Accepted answer

When they die, their backpack is erased. You're trying to save it after it is erased, so try something like:

wait(2) 

gpid = 188000708 -- Gamepass ID

local player = script.Parent.Parent
local GPS = game:GetService("GamePassService")

while true do
wait()
if player.Character.Humanoid.Health < 6 then -- If it is 5hp or less then
    if GPS:PlayerHasPass(player, gpid) then
        backup = player.Backpack:clone()
        backup.Parent = player.StarterGear
        end
    end
end

Sad thing is, if a player takes damage that instantly sets their HP to 0 or make it 0 from 50 instantly in one hit, you're going to have to retrofit a script to go into the damage-causing script to save it, as the above one will not have any time to save it.

You could fix this by making health drain after a player is hit, e.g. it quickly cycles through 50, 49, 48,... ...6, 5 (it is now saved), 4 , 3, 2, 1, 0, (DEAD).

1 comment

1

Ah alright, I thought the items would stay in their backpack until they respawned.

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