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

How does one produce an alternative to the touched:connect(ontouched) to a left click then touch?

The easiest questions to ask are the ones that seem like asking. I couldn't find any other scripts that held similar traits to the one I'm trying to script, and a search doesn't do me any better when I don't know the terms I'm trying to word.

The current script you'll see in the block allows the player to barely touch the ore and deal damage to it without having to left click. This is problematic if I want players to left click first.

Is there a function where a player will press mousebutton1 down and it'll put a timer waiting for the player to touch the ore?

axelvl = 1 --Damage to ore.
allyWood = 5 --Money from ore.
resettime = .5 --Wait time for reuse.

Tool = script.Parent
ting = 0 --Debounce.

function hit()
	print("hitting")
end

function onActivated() 
	if not Tool.Enabled then
		return
	end
	Tool.Enabled = false
	wait(1)
	Tool.Enabled = true
end 

function onTouched(hitt)
	if ting == 0 then
	ting = 1
	if hitt.Parent.Name == "Ore" then
	user = game.Players:findFirstChild(Tool.Parent.Name)
	hitt.Parent.hit.Value = hitt.Parent.hit.Value - axelvl
	script.Parent.Handle.SwingThree:Play()
	if hitt.Parent.hit.Value < 1 and hitt.Parent.Timber.Value == 0 then
		user.leaderstats.Frang.Value = user.leaderstats.Frang.Value + allyWood
		hitt.Parent.Timber.Value = 1
		script.Parent.Handle.EndSwing:Play()
		wait(resettime)
	else
		wait(1)
	end
	end
	ting = 0
	end
end

Tool.Activated:connect(onActivated)
connection = Tool.Blade.Touched:connect(onTouched)

1 answer

let me guess, it should be easy. instead of make it a open line in the script,

connection = Tool.Blade.Touched:connect(onTouched)

put it within the left button click event,

MouseButton1Click:connect(function ()
	connection = Tool.Blade.Touched:connect(onTouched)
end)

the above script is not complete. you need to find out where to put mousebutton, is it a GUI, or is it a part

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