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

How to script a newly touching object rather than a currently touching object?

I'm having an issue with an attack script, basically I need to do a strong punch. But the issue is that it only registers objects that have been touched after the script was ran, rather then if it was already touching something.

I'm using Instance.Touched:Connect(function(hit) btw

3 comments

0

I'm pretty new to scripting, also if it changes anything. The object that's being detected for contact is non-collide and transparent.

0

Sorry, are you trying to see what the instance is touching at the time of running or just what is newly touching the instance?

0

Oops, I put the title the wrong way round. I'm dumb. I meant I'm trying to detect what is currently touching it and if it's the right thing ( a humanoid ) then damage it.

1 answer

This is how you would detect if a player touched your instance

Part1.Touched:Connect(function(hit)
	local Player = Players:GetPlayerFromCharacter(hit.Parent) -- Checks and returns if the part associates to a player
	if Player then
		-- do dmg stuff
	end
end)

btw you might also need a debounce

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