Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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

1 answer

Log in to vote
0
Answered by 4 years ago

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.

Ad

Answer this question