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

Part follow script?

Asked by
Mystdar 352 Moderation Voter
10 years ago

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.

01tool = script.Parent
02 
03function onButton1Down(mouse)
04local target = mouse.Target
05  local q = Instance.new("Part", Workspace)
06q.Size = Vector3.new(3,3,3)
07q.Anchored = true
08q.CanCollide = False
09while true do
10wait()
11   q.CFrame = CFrame.new(Vector3.new(tool.Parent.Humanoid.TargetPoint.X,0,tool.Parent.Humanoid.TargetPoint.Z))
12end
13end
14function onEquipped(mouse)
15  mouse.Button1Down:connect(function () onButton1Down(mouse) end)
16end
17 
18tool.Equipped:connect(onEquipped)

(Apologies if I have tagged wrong/incorrectly)

1 answer

Log in to vote
3
Answered by 10 years ago

Try the following

01local tool = script.Parent
02local spawned = false
03 
04function onButton1Down(mouse)
05    if spawned then return end
06    local target = mouse.Target
07    local q = game.Lighting.Union:Clone()
08    q.Parent = Workspace
09    q.Size = Vector3.new(3,3,3)
10    q.Anchored = true
11    q.CanCollide = False
12    spawned = true
13    while spawned do
14        wait()
15        q.CFrame = CFrame.new(Vector3.new(tool.Parent.Humanoid.TargetPoint.X,0,tool.Parent.Humanoid.TargetPoint.Z))
View all 23 lines...
0
I will. Mystdar 352 — 10y
0
Wow, thanks! Mystdar 352 — 10y
0
No problem, good luck with your script! damagex443 325 — 10y
0
One problem, though, every time you click it clones it. Any Help? Mystdar 352 — 10y
View all comments (7 more)
0
add a local bool variable named Spawned and set it to false. Then when you click check if spawned is false otherwise return. damagex443 325 — 10y
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! Mystdar 352 — 10y
0
I've editted my post with a full script you can use. damagex443 325 — 10y
0
Question, what if the tool is not equipped, or if the player respawns? The part would still remain, correct? Spongocardo 1991 — 10y
0
Using my script? Mystdar 352 — 10y
0
Wow, thanks a lot damagex! Mystdar 352 — 10y
0
You're welcome, but take note of Spongocardo's comment above. You will probably need some more code to hande respawns and unequips. damagex443 325 — 10y
Ad

Answer this question