I am trying to make a area where it gives you the item when your in it and takes it when your not and it don't work pls help. Aso i am getting the error on the first code of " 17:55:17.115 - Workspace.Part.Script1:3: attempt to index nil with 'Backpack'"
while true do script.Parent.Touched:Connect(function() game.ServerStorage.BuildingHammer:MoveTo(Vector3.new(game.Players.LocalPlayer.Backpack)) end) wait(1) end
while true do script.Parent.TouchEnded:Connect(function() game.Players.LocalPlayer.Backpack.BuildingHammer:Moveto(game.ServerStorage) end) wait(1) end
I think you've got the whole concept of
MoveTo wrong. First off you use
MoveTo to move an object with a humanoid to a
For More Detail On '
Humanoid:MoveTo()' click this API link:
Humanoid:MoveTo ROBLOX Developer You don't use it to move items into player's backpack, to move an object just parent it to a new place. E.g.
game.ServerStorage.BuildingHammer.Parent = --Player's Backpack
Also, i assume you are doing this in a
server script. If this is true then local player won't work. Local Player only works for local scripts as local scripts are ran on the client, not the server so you use the playerAdded event like so:
game.Players.PlayerAdded:Connect(function(Player) --Save Player to a variable as first parameter
Also you don't have to put it in a while true do loop, there's just no point. You don't have to check for when the player touches the part constantly, the
Touched event does that. Also using ''Region3'' would probably be recommended for this as you can detect whether a player is within a certain area. If you want to learn this you can watch the DevKing's Tutorial here: DevKing Advanced Series: Region3
Hope this helps!