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

How to put function out of loop and only make one connection?

How can I make only one connection instead of multiple connections to the function?


--Variables
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local goodfarm = game.ServerStorage.GoodFarm
local badfarm = game.ServerStorage.BadFarm
local Farm = game.ServerStorage.Farm
local FarmClone
local Debounce = false
local found = game.ServerStorage:FindFirstChild("GoodFarm")
local found2 = game.ServerStorage:FindFirstChild("BadFarm")
local ClonedFarm = nil
--Move Part to Mouse Position Always
while true do
	print(mouse.Target)
	
	--Good
	if mouse.Target == game.Workspace.Island then
		mouse.TargetFilter = goodfarm
		badfarm.Parent = game.ServerStorage
		
		if found then
			goodfarm.Parent = workspace
		end
		goodfarm.Position = mouse.Hit.p
		
		
		
--Problem  |
--             \/
		mouse.Button1Down:connect(function()
			FarmClone = Farm:Clone()
			FarmClone.Parent = workspace
		end)




	end
	--Bad
	if mouse.Target == game.Workspace.Water then
		goodfarm.Parent = game.ServerStorage
		mouse.TargetFilter = badfarm
		
		if found2 then
			badfarm.Parent = workspace
		end
		
		badfarm.Position = mouse.Hit.p
	end
	
	if Debounce == true then
		goodfarm.Parent = game.ServerStorage
		badfarm.Parent = game.ServerStorage
		break
	end
	wait()
end




2 comments

0

remove the while loop and put your if statements in the function.

0

Heres a video why that wont work. https://www.youtube.com/watch?v=wnyjtkUSP1k

1 answer

mouse.Button1Down:wait()

waits until the event is fired

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