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

[Solved] Problem with script not recognizing players backpack?

Asked by 5 years ago
Edited 5 years ago

I've made a detector script which sees if a player has a tool in their backpack called "LavaKey" and then if so opens a door by making it invisible and then waits 8 seconds and closes it. The issue is I cant seem to get the line that sees if the key is in the backpack correct and when I run the game and step on the detector I get an error on line 10 saying that "Backpack is not a valid member of Model" but then after that I get no more errors. (That error may be referring to the door thats on the detector or something but it doesnt have a humanoid. Anyone know what I need to fix? Thx.

local detector = script.Parent
local door = game.Workspace.LavaDoor
DB = true

detector.Touched:Connect(function(hit)
    if DB == true then
        DB = false
        if hit.Parent:FindFirstChild('Humanoid') then
            local hum = hit.Parent:FindFirstChild('Humanoid')
            if hit.Parent.Backpack:FindFirstChild("LavaKey") then--here
                door.Transparency = 1
                door.CanCollide = false
                wait(8)
                door.Transparency = 0
                door.CanCollide = true
            elseif not hit.Parent.Backpack:FindFirstChild("LavaKey") then
                hum:TakeDamage(20)
            end
        wait(2)
        DB = true
        end
    end

end)
0
i ended up fixing it by using, "local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)" JakeDaBeAat 13 — 5y

1 answer

Log in to vote
0
Answered by
Hizar7 102
5 years ago

The backpack is not in the character in workspace, which is where you are looking, you need to access the players backpack in the game.players, which can be done by

game:GetService:("players")

Sorry for not writing out a script that will get the player exactly how you need it to but i think this should answer your question if you're aware on how to get players from the player folder, Let me know!

0
you don't need another semi colon after GetService. game:GetService("Players") hellmatic 1523 — 5y
0
ok i can do what you wrote but how can i then reference the player that hit the detector as game.GetService("players") JakeDaBeAat 13 — 5y
Ad

Answer this question