How can I disconnect this function in a server script?
Asked by
4 years ago Edited 4 years ago
I swear I was able to disconnect functions before but I seem to have forgotten. I have it so that when the player holds G, it fires a remote event which then activates the function, and when they release G it fires another remote event which is supposed to disconnect the function. I'm having a little trouble with that part. At first I tried this:
01 | function bandaging(plr) |
02 | local humanoid = plr.Character:WaitForChild( "Humanoid" ) |
03 | local wounds = humanoid.Wounds |
05 | if humanoid.Health > 0 then |
06 | if wounds.Value > 0 then |
07 | wounds.Value = wounds.Value - 1 |
17 | Bandaging.OnServerEvent:Connect(bandaging) |
19 | CancelBandaging.OnServerEvent:Disconnect(bandaging) |
And then I got an error on the last line saying I couldn't use Disconnect I think. So then I tried changing it to lowercase and then got an error saying it was deprecated. My final attempt was this:
01 | function bandaging(plr) |
02 | local humanoid = plr.Character:WaitForChild( "Humanoid" ) |
03 | local wounds = humanoid.Wounds |
05 | if humanoid.Health > 0 then |
06 | if wounds.Value > 0 then |
07 | wounds.Value = wounds.Value - 1 |
17 | function cancelBandaging() |
18 | bandaging:Disconnect() |
21 | Bandaging.OnServerEvent:Connect(bandaging) |
23 | CancelBandaging.OnServerEvent:Connect(cancelBandaging) |
And that also didn't work. It said I was trying to index function with Disconnect. Any help is appreciated.