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

Part follow script?

In this script a part will follow the mouse, I just want to know how you would use a Union from the lighting instead of a part, thanks.

tool = script.Parent

function onButton1Down(mouse)
local target = mouse.Target
  local q = Instance.new("Part", Workspace)
q.Size = Vector3.new(3,3,3)
q.Anchored = true
q.CanCollide = False
while true do
wait()
   q.CFrame = CFrame.new(Vector3.new(tool.Parent.Humanoid.TargetPoint.X,0,tool.Parent.Humanoid.TargetPoint.Z))
end
end
function onEquipped(mouse)
  mouse.Button1Down:connect(function () onButton1Down(mouse) end)
end

tool.Equipped:connect(onEquipped)

(Apologies if I have tagged wrong/incorrectly)

1 answer

✓ Accepted answer

Try the following

local tool = script.Parent
local spawned = false

function onButton1Down(mouse)
	if spawned then return end
	local target = mouse.Target
	local q = game.Lighting.Union:Clone()
	q.Parent = Workspace
	q.Size = Vector3.new(3,3,3)
	q.Anchored = true
	q.CanCollide = False
	spawned = true
	while spawned do
		wait()
		q.CFrame = CFrame.new(Vector3.new(tool.Parent.Humanoid.TargetPoint.X,0,tool.Parent.Humanoid.TargetPoint.Z))
	end
end

function onEquipped(mouse)
  mouse.Button1Down:connect(function () onButton1Down(mouse) end)
end

tool.Equipped:connect(onEquipped)

11 comments

0

I will.

0

Wow, thanks!

0

No problem, good luck with your script!

0

One problem, though, every time you click it clones it. Any Help?

0

add a local bool variable named Spawned and set it to false. Then when you click check if spawned is false otherwise return.

0

I have never worked with bool variables, if you want to write it out, that would be great, otherwise, i'll just post it as a new question, thanks!

0

I've editted my post with a full script you can use.

0

Question, what if the tool is not equipped, or if the player respawns? The part would still remain, correct?

0

Using my script?

0

Wow, thanks a lot damagex!

0

You're welcome, but take note of Spongocardo's comment above. You will probably need some more code to hande respawns and unequips.

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