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.

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

Log in to vote
3
Answered by 10 years ago

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)

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