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

how would i make this only work if tool is equipped and click the button?

local script:

f= true
local mouse = game.Players.LocalPlayer:GetMouse()


script.Parent.Parent.Equipped:Connect(function()
	mouse.Button2Down: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)

1 answer

There is an event in a tool called Tool.Activated which fires every time you click.

local f = true

script.Parent.Parent.Activated:Connect(function()
 
        if f then
            f = false
            if workspace:FindFirstChild("orangeportal") then
                workspace.orangeportal:Destroy()
            end
        local orangeportal = Instance.new("Part")
        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.Parent = workspace
        orangeportal.Touched:Connect(function(hit)
            if game.Workspace:FindFirstChild("blueportal") then
            hit.CFrame = CFrame.new(workspace.blueportal.CFrame.lookVector * 10)
            else
                return
            end
        end)
        wait()
        f = true
        end
end)

It made it a bit hard to understand your code but all I did was change the equip event with an activated event and fixed some other issues like changing game.Workspace to workspace and also replacing any Instance.new() parent arguments with parenting the instance after manipulating the properties.

4 comments

0

ye i tried this but it dont work the way i want it to work

0

also i want it to only do that when i click mouse button 2

0

Oh, I see.

0

Within the parameters of the equipped event you should put Mouse, and then you can use it wherever.

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