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

attempt to index upvalue 'Torso' (a nil value) what is this?

Asked by 8 years ago

hey i am trying to get a normal part to go were i click on the map that i have built would anyone know how to do this i am really stuck

1 answer

Log in to vote
0
Answered by 8 years ago

You obtain the mouse using Player:GetMouse(). Then there is a property within the mouse called Hit that will get the 3D position the mouse is pointing at in CFrame form. With that information you can reset the position of the brick to the Player's mouse when the player clicks using the Button1Down() event.

http://wiki.roblox.com/index.php?title=API:Class/Mouse <- wiki

--In a local script


player = game.Players.LocalPlayer mouse = player:GetMouse() --Get the mouse from the player local part = PathToPartHere --part you want to move with the mouse mouse.Button1Down:connect(function() --Mouse button is clicked part.CFrame = mouse.Hit --Set the new brick position to the mouse hit property end) --This should work. Use Remote Functions/Events if FE is enabled to change the position of the brick
0
i trey that and the game is telling me that there is a error that i am attempting to call mouse a nil value on line 5 thefungamerlol 1 — 8y
0
I believe GetMouse can only be called from localscripts. Put this code into a LocalScript and leave it in the player. Get rid of the event at the start and just do: local mouse = game.Players.LocalPlayer:GetMouse() darkelementallord 686 — 8y
0
Yea sorry, I'll fix it rn dragonkeeper467 453 — 8y
0
lol now it is saying this i feel like you guys have the right code but i am doing something wrong? 13:08:06.886 - Players.Player1.PlayerScripts.LocalScript:5: attempt to index upvalue 'part' (a nil value) thefungamerlol 1 — 8y
0
replace PathToPartHere, with the correct path to the part in your workspace, this script will NOT work if you have FE enabled under game.Workspace properties. If you wish to use this with FE, lookup remote functions on the wiki dragonkeeper467 453 — 8y
Ad

Answer this question