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

.Touched Event Not Firing?(Hopeless, Ignore this)

This is my first time asking a question here so I apologize in advance if I break any rules or customs.

I'm making a game where players can be 'infected', and to do this I have spheres that will kind of float around until they touch something other than a player. I have an extremely simple function that runs as soon as the .Touched event fires, and yet when I run the game the function does not fire when it touches the ground. I have searched all over the internet for an explanation of this, but was unable to solve my problem.

I did discover (Correct me if I'm wrong) that for .Touched to work, there must be a Touch Interest object parented to the Base Part that the script refers to. Normally this would be fine, but I think that because my sphere is a clone it doesn't have the touch interest. I don't really know why, but the function simply refuses to run at all. Here's my script:

coughDroplet = script.Parent

coughDroplet.Touched:Connect(function(hit)
	print("Cough droplet has been touched")
	if hit.Name == "Infectable" then
		print("Anchoring Droplet")
		coughDroplet.Anchored = true
	else
		if hit.Parent.Humanoid ~= nil then
			print("Infecting Player")
			local humanoid = hit.Parent.Humanoid
			local player = humanoid.Parent:GetPlayerFromCharacter()
			game.ReplicatedStorage.TellInfectedClient:FireAllClients(player, coughDroplet.PlayerID.Value)
		end
	end
end) 

3 comments

0

Sorry about the formatting of the code, I didn't realize it would do that.

0

Never mind, fixed it

0

I meant I fixed the formatting, not the code. The code still doesn't work

1 answer

While I wouldn't mind figuring out why this never worked, I ended up just learning how to use ray casting instead to do what I was trying to do with .Touched. No need to answer this.

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