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

What is wrong in my script which checking player inventory?

Hi, I'm making tool which checking inventory for tool and I'm doing something bad but I don't know what. Anyone know what's wrong?

local player = game:GetService("Players").Backpack

script.Parent.Touched:connect(function(hit) 
	if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
	if player.Backpack:FindFirstChild("Tool name goes here") then
    print("Tool exists")
	end
	end
end)

1 answer

Here is repaired script:

script.Parent.Touched:connect(function(hit)
	    if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	    if player.Backpack:FindFirstChild("Tool name goes here") then
	    print("Tool exists")
				end
	   end
	end)

you did not get the player right, you made line 1 completely wrong, if you use global script then do it like this.

2 comments

1

You should explain what you're doing.

1

Explanation: Your line 1 was wrong, i can't explain it why it was just very very wrong, you can not do that, to get the player backpack in a server script you need to use line 3 that i made which in brackets there is your character, and :GetPlayerFromCharacter is function that gets the player from character, i did not change anything except that line. Hope you understood.

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