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

Mouse Tool Spawn on Click?

So I made this script that a group of parts is copied from Lighting, and is moved to the position where the mouse is at that moment. I may have made it TOTALLY WRONG, and if so I'd like a wiki link (Or if you want to fix it that would be great too) as to how to fix it, or simple instructions. (See below the script for whats not working)

dum=game.Lighting.Dummy

plr=script.Parent.Parent.Parent

mouse=plr:GetMouse()

mouse.Button1Down:connect(function()

	h=mouse.Hit
	c=dum:Clone()
	c.Parent=game.Workspace
	
	nh=h+Vector3.new(0,5,0)

c:MoveTo(Vector3.new(nh))
end)

So far, it clones the dummy, and it appears on click. But it always teleports to the same spot no matter where I click. I assume I may have used Hit or Moveto incorrectly.

1 answer

✓ Accepted answer

You didn't use mouse.Hit correctly. Here is the corrected script: And make sure the dummy has a torso!

player = game.Players.LocalPlayer
mouse = player:GetMouse()

mouse.Button1Down:connect(function(m)
	local clone = game.Lighting.Dummy:Clone()
	clone.Parent = game.Workspace
	
	clone.Torso.CFrame = CFrame.new(mouse.Hit.p) + Vector3.new(0, 5, 0)
end)

3 comments

0

Edited the final one. You're welcome :)

0

I feel so stupid haha, thanks.

0

No problem :)

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