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

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

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

✓ Accepted answer

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

5 comments

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

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()

0

Yea sorry, I'll fix it rn

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)

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

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