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

Why does this not put the wand in my backpack?

This is inside a part in Workspace.

local part = script.Parent

function onTouch(player) 
local wand = game.ReplicatedStorage.Tool:Clone()
wand.Parent = player.Backpack
end


script.Parent.Touched:connect(onTouch)

I get this error Backpack is not a valid member of Part

1 answer

✓ Accepted answer

The Touch Parameter returns your the object that triggered the event to access the Player you'll need to use GetPlayerFromCharacter()

local part = script.Parent

function onTouch(player) 
local wand = game.ReplicatedStorage.Tool:Clone()
local Player = game.Players:GetPlayerFromCharacter(player.Parent)--Getting the Player using the Character.
if Player then--This prevent errors from occurring, like for example if your function was triggered by an object it won't have a Backpack would it?
wand.Parent = Player.Backpack
	end
end


script.Parent.Touched:connect(onTouch)

~UserOnly16Charcters, Hoped I helped you to answer your question! If you have any further question, don't hesitate to comment below!!

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