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

Why not set the object's position?

Sorry for Google Translator

local player = game.Players.LocalPlayer
local charecter = player.Character
local mouse = player:GetMouse()

mouse.Button1Down:connect(function()
	local stone = game.ReplicatedStorage.stone:Clone()

	if mouse.Target ~= nil then
		stone.Parent = workspace
		stone.Position = Vector3.new(mouse.Target)
	end
end)
	

What have I done wrong? if you remove the line

stone.Position = Vector3.new(mouse.Target)

, the code works well. According to my idea object "stone" should be created on the mouse coordinates

1 comment

0

I think Mouse.Target returns the object that the mouse is pointing at, not a Vector3 position

2 answers

✓ Accepted answer

The problem is on line 10, you are using Vector3.new() incorrectly.

To fix this, all you have to do is set the stone's position to the target's position.

stone.Position = mouse.Target.Position

Vector3.new() takes in 3 values: x, y, and z. You are just putting in the object.

The problem is here is that you're using wrong properties of mouse!

Since using mouse.Target.Position will return the coordinates of object that the mouse it pointing at. While mouse.Hit.p will return the coordinates of where your mouse is pointing which is what you want, correct?

So change line 10 to: stone.Position = mouse.Hit.p

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