Hey so I am making a path generator and it is doing something unexpected.
I currently have two paths, different colours. When I hold LMB both colours generate randomly but I obviously don’t want that.
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Pressed = false
local Color = Color3.fromRGB(255, 170, 0)
script.Parent.Equipped:Connect(function()
UserInputService.InputBegan:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
Pressed = true
end
end)
UserInputService.InputEnded:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
Pressed = false
end
end)
while true do
if Pressed then
local Path = game:GetService("ReplicatedStorage"):WaitForChild("Path"):Clone()
Path.Parent = workspace:WaitForChild("Paths")
Path.Position = HumanoidRootPart.Position - Vector3.new(0, 2, 0)
Path.Color = Color
Path.Anchored = true
Path.CanCollide = true
Path.Transparency = 0.5
spawn(function()
wait(5)
for i = Path.Transparency, 1, Path.Transparency / 5 do
Path.Transparency = i
wait()
end
if Path.Transparency == 1 then
Path:Destroy()
end
end)
end
wait()
end
end)