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

Backpack isn't a valid member of Player help?

So here i go again asking i just need to know what did i do wrong, because this is the script

local tool = script.Parent
local player = game.Players.player

tool.Equipped:connect(function(mouse) 
    print("Tool equipped!")

    	tool.Activated:Connect(function() 
        print("Mouse pressed!")
        local tool2 = game.Lighting.Revolver
        tool2:Clone().Parent = player.Backpack

        wait(0.5)

        tool:Destroy()

    end)
end)

and after i test it out it said Backpack isn't a valid member of Player (this is not local script this is normal script) i need to know why it doesn't read player's inventory.

3 comments

0

LocalPlayer can only be indexed from LocalScripts

0

oh thank you i will try it out

0

nope doesnt work

1 answer

You need to call the player correctly,, Since this is a server script, it won't be able to detect a "Local"Player, as Sinister said earlier. You'll need to call the player some other way.

There are a few ways to do this,

game.Players.PlayerAdded:Connect(function(player)

I wouldn't doubt if you've heard of "game.Players.PlayerAdded", it's very useful for server scripts, It will run the function whenever a; player is added to the game service "Players" The argument "(player)" is the, in other words, LocalPlayer you're searching for.

Another way is through RemoteEvents, I most commonly use RemoteEvents as a way to get the local player in a server script. I recommend you doing some research on RemoteEvent's, they're extremely crucial to scripting. They can be a lil' tricky at the start to understand and grasp, but once you learn how they work, and etc. I'm sure they'll make your job wayy easier!

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