- What do I want to achieve?
The first time the tool is clicked (while being equipped) I want it to fetch the part they clicked on (THAT WORKS!), then I want it to make the textlabel above it say "Connect second part."
(THAT WORKS!), the second time a different part is clicked, I want it to start the connecting process (as shown in the script) but instead all it does is show “Connect second part” when I click the second part
- What is the issue? Include screenshots / videos if possible!
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried to get help from the unofficial discord server, but they couldn’t find out what.
local UIS = game:GetService("UserInputService")
script.Parent.Equipped:Connect(function()
local plr = script.Parent.Parent.Name
print("Hammer equipped by " .. plr)
for _, child in pairs(workspace:GetDescendants()) do
if child:IsA("BasePart") and child.Name == "part" then
if child.Editable.Value == true then
child.GUI.CT.Visible = true
end
end
end
end)
script.Parent.Unequipped:Connect(function()
print("Hammer unequipped")
for _, child in pairs(workspace:GetDescendants()) do
if child:IsA("BasePart") and child.Name == "part" then
if child.Editable.Value == true then
child.GUI.CT.Visible = false
end
end
end
end)
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then
return
end
local plr = script.Parent.Parent.Name
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local mouse = UIS:GetMouseLocation()
local ray = game.Workspace.CurrentCamera:ScreenPointToRay(mouse.X, mouse.Y)
local hit = workspace:Raycast(ray.Origin, ray.Direction * 100)
if hit and hit.Instance:IsA("BasePart") and hit.Instance.Name == "part" then
if hit.Instance.Editable.Value == true then
local firstpart = "df"
local secondpart = "df"
local lastlclick = "df"
if firstpart == "df" then
firstpart = hit.Position
hit.Instance.GUI.CT.Text = "Connect second part."
lastlclick = hit.Instance.Name
print(firstpart)
print(secondpart)
elseif secondpart == "df" and firstpart ~= "df" and hit.Position ~= firstpart then
secondpart = hit.Instance.Name
hit.Instance.GUI.CT.Text = "Connecting 1/2"
lastlclick.GUI.CT.Text = "Connecting 1/2"
task.wait(2)
hit.Instance.GUI.CT.Text = "Connecting 2/2"
lastlclick.GUI.CT.Text = "Connected 2/2"
task.wait(1)
hit.Instance.GUI.CT.Text = "Connected"
lastlclick.GUI.CT.Text = "Connected"
print(firstpart)
print(secondpart)
end
end
end
end
end)
I’m more new to scripting, and thanks for the help to the people who are whilling to help me!