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
Sorry about the formatting of the code, I didn't realize it would do that.
Never mind, fixed it
I meant I fixed the formatting, not the code. The code still doesn't work