Script works only 50% of the time

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    That it works 100% of the time, duh.

  2. What is the issue? Include screenshots / videos if possible!
    it only works 50% of the time.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have messed with the variables and angles a Li’l bit.

So here’s what I have right now: let me know why it is only working 50% of the time???

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Button1Down:Connect(function()
	print(mouse.Hit.Position)
	local StraightPipe = script.Straight_pipe
	if mouse.Target.Name =="A-Inlet" then
		local pipe = StraightPipe:Clone()
		pipe.Parent = game.Workspace.pipefolder
		pipe:SetPrimaryPartCFrame(mouse.Target.CFrame*CFrame.Angles(0,math.rad(180),0))
	elseif mouse.Target.Name == "B-Outlet" then
		local pipe = StraightPipe:Clone()
		pipe.Parent = game.Workspace.pipefolder
		pipe:SetPrimaryPartCFrame(mouse.Target.CFrame*CFrame.Angles(0,math.rad(180),0))
	elseif mouse.Target.Name == "C-Inlet" then
		local pipe = StraightPipe:Clone()
		pipe.Parent = workspace.pipefolder
		pipe:SetPrimaryPartCFrame(mouse.Target.CFrame*CFrame.Angles(0,math.rad(180),0))
	elseif mouse.Target.Name == "D-Outlet" then
		local pipe = StraightPipe:Clone()
		pipe.Parent = game.Workspace.pipefolder
		pipe:SetPrimaryPartCFrame(mouse.Target.CFrame*CFrame.Angles(0,math.rad(180),0))
	end
end)
mouse.Button2Down:Connect(function()
	if mouse.Target.Parent.Parent == workspace.pipefolder then
		mouse.Target.Parent:Destroy()
	end
end)

please help. I need it.

sorry I haven’t explained the problem correctly, so what it does is it builds one pipe, and then it just builds inside of itself.

1 Like

It sometimes happens to me aswell.

1 Like

Can you explain exactly what the problem is here so people can understand the problem and be able to help you?

2 Likes

What are you trying to do? I cleaned your code a bit so it’s easier to understand.

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local mouse = player:GetMouse()

local names = {"A-Inlet", "B-Outlet", "C-Inlet", "D-Outlet"}

local rotation = CFrame.Angles(0, math.rad(180), 0)

mouse.Button1Down:Connect(function()
	print(mouse.Hit.Position)
	local StraightPipe = script.Straight_pipe
	local target = mouse.Target
	if target and table.find(names, target.Name) then 
		local pipe = StraightPipe:Clone() 
		pipe.Parent = workspace.pipefolder 
		pipe:SetPrimaryPartCFrame(target.CFrame*rotation)
	end
end)

mouse.Button2Down:Connect(function()
	local target = mouse.Target 
	if not target then return end 
	local model = target.Parent 
	if not model then return end 
	if model.Parent == workspace.pipefolder then 
		model:Destroy()
	end
end)
2 Likes

I’m not quiet sure, but recently i’ve been noticing that my scripts haven’t been working aswell. It might just be the Servers lagging or having a some slight issues right now.

Have a nice day!

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Button1Down:Connect(function()
print(mouse.Hit.Position)
local StraightPipe = script.Straight_pipe
if mouse.Target.Name ==“A-Inlet” then
local pipe = StraightPipe:Clone()
pipe.Parent = game.Workspace.pipefolder
pipe:SetPrimaryPartCFrame(mouse.Target.CFrameCFrame.Angles(0,math.rad(180),0))
end
if mouse.Target.Name == “B-Outlet” then
local pipe = StraightPipe:Clone()
pipe.Parent = game.Workspace.pipefolder
pipe:SetPrimaryPartCFrame(mouse.Target.CFrame
CFrame.Angles(0,math.rad(180),0))
end
if mouse.Target.Name == “C-Inlet” then
local pipe = StraightPipe:Clone()
pipe.Parent = workspace.pipefolder
pipe:SetPrimaryPartCFrame(mouse.Target.CFrameCFrame.Angles(0,math.rad(180),0))
end
if mouse.Target.Name == “D-Outlet” then
local pipe = StraightPipe:Clone()
pipe.Parent = game.Workspace.pipefolder
pipe:SetPrimaryPartCFrame(mouse.Target.CFrame
CFrame.Angles(0,math.rad(180),0))
end
end)
mouse.Button2Down:Connect(function()
if mouse.Target.Parent.Parent == workspace.pipefolder then
mouse.Target.Parent:Destroy()
end
end)