Alright, as the title states, I'm having issues finding the backpack of the player who clicked a block. As of now, I have this code:
script.Parent.ClickDetector.MouseClick:connect(function(hit) script.Parent:Destroy() -- correctly destroys. print(hit) game.Lighting.tools.Matches:Clone().Parent = game.Players:GetPlayerFromCharacter(hit).Backpack end)
As the comment states, the destroy works (as I'd expect), however, it won't clone into the designated location. Whenever I'm in solo mode, I get this in the output:
Workspace.Drawer.Matches.Script:4: attempt to index a nil value
If I'm actually in-game, it then displays the error at line 3 instead of 4.
This is NOT a LocalScript. game.Lighting.tools.Matches
does exist.
I've read that you can't reference the player through click detection, but I've even bypassed that in the conversion of a tycoon from touch to click detection buttons, letting me know it has to be possible somehow (the method I used for the tycoon didn't function here, sadly).
Thank you for reading, and I hope to find a solution to this issue!
You are able to get the player value from this event. If you look on the wiki, you would get this example.
local CD = script.Parent local function onMouseClick(Player) local Brick = CD.Parent if Brick:IsA("BasePart") then Brick.BrickColor = Player.TeamColor end end CD.MouseClick:connect(onMouseClick)
function clicked(player) -- Use the player variable for a path to the player object