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

can someone please make this portal gun work properly?

Asked by 5 years ago

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 answer

Log in to vote
1
Answered by 5 years ago

First is you can make a flag to set whether the tool has been equipped or not.

local eq = false local tool = script.Parent.Parent

tool.Equipped:Connect(function() eq = true end)

tool.Unequipped:Connect(function() eq = false end)

Then its

mouse.Button1Down:Connect(function() if (eq == true) then kill orangeportal, make orange port. rest of code. end end)

I don't think you should be connecting code each click, that should be done once. Fairly sure it doesn't overwrite, so 10 clicks is 10 connects of that code block (when you then equip, it would run 10 blocks of code). Here, we connect it once to the mouse click, if its equipped, do it, otherwise does nothing.

But I didn't test this, or figure out what exactly your doing, but this should help.

0
thanks for the idea, works now Gameplayer365247v2 1055 — 5y
Ad

Answer this question