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

why am i getting the error "Disconnect is not a valid member of RBXScriptSignal" ?

Asked by 1 year ago

heya

i wanted to create a text block that appears when a certain character dies,, though ive put it in kinda weirdly..

i want the heartbeat runservice to disconnect when the enemy is killed,, but i keep getting the same "Disconnect is not a valid member of RBXScriptSignal" error when the character does die

print("YES I DO ANYTYING AT ALL HI")

local RunService = game:GetService("RunService")
local Players = game:GetService("Players") 
local open = false
local heartbeathaha = RunService.Heartbeat

heartbeathaha:Connect(function() 
    if workspace.megabob.Humanoid.Health == 0 then
        heartbeathaha:Disconnect(function()
        print("MEGABOB DEAD YES HI")
        local StarterGui = Players:WaitForChild("PlayerGui")
        local ScreenGui = StarterGui.bobquestion1
        local Frame = ScreenGui.Frame
        Frame.Visible = true
        if open == false then
            open = true
            Frame.Visible = true
            wait(4)
            Frame.Visible = false
            ScreenGui = StarterGui.bobquestion2
            Frame = ScreenGui.Frame
            Frame.Visible = true
            open = true
            Frame.Visible = true
            wait(4)
            Frame.Visible = false
            heartbeathaha:Disconnect()
            end
        end)
    else
        print("THIS CODE WORKS CORRECTLY")
        open = false
        local StarterGui = Players:WaitForChild("PlayerGui")
        local ScreenGui = StarterGui.bobquestion1
        local Frame = ScreenGui.Frame
        Frame.Visible = false
        print("THIS CODE WORKS VERY CORRECTLY")
end
end
)


can someone tell me what exactly is going wrong here..? im not the greatest at troubleshooting

1 answer

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

The reason for this error is exactly what the error says; the Disconnect method is not a member of RBXScriptSignal. You're trying to use the Disconnect method on the Event itself which isn't a member of that data type.

The Disconnect method is a member of the RBXScriptConnection data type. The RBXScriptConnection, known as the Connection, is an object returned by the Connect method of an Event. This is used to disconnect a function from an Event.

local RunService = game:GetService("RunService")
local heartbeathaha = RunService.Heartbeat

local connection
connection = heartbeathaha:Connect(function() -- Connects the function to the event and returns the connection object.
    if workspace.megabob.Humanoid.Health == 0 then
        connection:Disconnect()
    end
end)

Documentation

RBXScriptSignal, RBXScriptConnection, Disconnecting Functions from Events

Ad

Answer this question