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

Script doesn't respawn the player if there is no tool. (?)

I am making a simulator game where they can buy better tools. Sometimes, they don't spawn with the tool for some weird reason. I made this script that detects if they have the tool. When they don't have it, it errors not finding the tool, here is my script.

game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
wait(1)
local tool = plr.BackPack.Tool
If tool then
print(plr.." has tool")
else
char:LoadCharacter()
print("Respawning".. plr)
end
end)
end)

The script should respawn them if there is no tool, it errors on line 5 when they don't have the tool, if they have the tool it works fine.

I want to thank everybody that spends their time trying to help me, even if they don't know the answer.

Best Wishes, JailBreaker_13

2 comments

0

it may be because the P in BackPack is capitalized.

0

I am on mobile right now. It is not the problem.

3 answers

✓ Accepted answer

Hey there, use FindFirstChild to check if the object exists or not, like so.

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        wait(1)
        if plr.Backpack:FindFirstChild('Tool') then
            print(plr.." has tool")
        else
            char:LoadCharacter()
            print("Respawning".. plr)
        end
    end)
end)

2 comments

0

Thanks, i will have to try it. I am on mobile right now, i will accept it if it works.

0

It works! The only error i had was it is plr:LoadCharacter, not char:LoadCharacter tysm

youy put a capital i on if

2 comments

0

Cause im on mobile. It says that it cant find the tool when it is not there. It errors instead of running.

0

you could try ~= nil

like quinzt said, you put a capital on if,=. I also formatted your code

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		wait(1)
		local tool = plr.BackPack.Tool
		if tool then
			print(plr.." has tool")
		else
			char:LoadCharacter()
			print("Respawning".. plr)
		end
	end)
end)

1 comment

0

Cause im on mobile. It says that it cant find the tool when it is not there. It errors instead of running.

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