so im trying to make kind of a portal gun that creates 2 different portals depending on what button you click down (mouse button 1 and mouse button 2) they create different portals but i want them to only get new position when you click down the button and have the tool equipped, not as it works now, here is the local script:
f = true
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button2Down:Connect(function()
script.Parent.Parent.Equipped:Connect(function()
if f then
f = false
if game.Workspace:FindFirstChild("orangeportal") then
game.Workspace.orangeportal:Destroy()
end
local orangeportal = Instance.new("Part",game.Workspace)
orangeportal.CanCollide = false
orangeportal.Size = Vector3.new(2,8,2)
orangeportal.Anchored = true
orangeportal.Name = "orangeportal"
orangeportal.BrickColor = BrickColor.new("Neon orange")
orangeportal.CFrame = CFrame.new(mouse.Hit.p)
orangeportal.Touched:Connect(function(hit)
if game.Workspace:FindFirstChild("blueportal") then
hit.CFrame = CFrame.new(game.Workspace.blueportal.CFrame.lookVector * 10)
else
return
end
end)
wait()
f = true
end
end)
end)
mouse.Button1Down:Connect(function()
script.Parent.Parent.Equipped:Connect(function()
if f then
f = false
if game.Workspace:FindFirstChild("blueportal") then
game.Workspace.blueportal:Destroy()
end
local blueportal = Instance.new("Part",game.Workspace)
blueportal.CanCollide = false
blueportal.Size = Vector3.new(2,8,2)
blueportal.Anchored = true
blueportal.Name = "blueportal"
blueportal.BrickColor = BrickColor.new("Baby blue")
blueportal.CFrame = CFrame.new(mouse.Hit.p)
blueportal.Touched:Connect(function(hit)
if game.Workspace:FindFirstChild("orangeportal") then
hit.CFrame = CFrame.new(game.Workspace.orangeportal.CFrame.lookVector * 10)
else
return
end
end)
wait()
f = true
end
end)
end)

1 comment
thanks for the idea, works now