Ad
Log in to vote
0

ClearAllChildren is not valid member of RBXScriptSignal?

Asked by 22 days ago
Edited 22 days ago

So im not the best scripter but i tried rewriting this 2 times still same error

I started working on game on roblox and i needed this script to work for me to go forward in project.

Got stuck on this script which is called Activated, it tool script for it to fire event when tool is activated, please note the script is not finished that why there are blank functions

Here is script:

local replicatedStorage = game:GetService("ReplicatedStorage") 

local Shared = replicatedStorage:WaitForChild("Shared")|
local Remotes = Shared:WaitForChild("Remotes") 
local sword = script.Parent 

local function activated() 
    Remotes.On_Tool_Activation:FireServer() |
end 

local function equipped() 
    print("Function_Equipped:Function not finished") 
end

local function unequipped()
    print("Function_Unquipped:Function not finished")
end

sword.Equipped:Connect(equipped)
sword.Unequipped:Connect(unequipped)
sword.Activated:ClearAllChildren(activated)

Game output bellow

 02:45:35.195  ClearAllChildren is not a valid member of RBXScriptSignal  -  Client - Activated:20
  02:45:35.196  Stack Begin  -  Studio
  02:45:35.196  Script 'Players.RexPROGaming09.Backpack.SpartanSword.Activated', Line 20  -  Studio - Activated:20
  02:45:35.196  Stack End  -  Studio
  • UPDATED -

This is from a tutorial on youtube becuse im training for making games solo I dont know much about script but here explaination

So there are 2 values in the sword and this localscript which makes error Localscript is called activated and it connected to modulescript called RemoteController. When user holds sword in hand and clicks it localscript will activate function and event here is other script

local Players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local Shared = replicatedStorage:WaitForChild("Shared")
local Remotes = Shared:WaitForChild("Remotes")
local remoteController = {}

local cooldownTable = {}

function remoteController.OnToolActivation(player)
    local currency = "Strenght"
    local character = player.Character or nil
    if character ~= nil then
        local tool = character:FindFirstChildOfClass("Tool") or nil
            if tool ~= nil then
            local amount = tool.Amount.Value
            local cooldown = tool.Cooldown.Value

            if not cooldownTable[player.Name] then
                cooldownTable[player.Name] = true
                player.leaderstats[currency].Value += amount
                wait(cooldown)
                cooldownTable[player.Name] = false
            end
        end
    end
end

Remotes.On_Tool_Activation.OnServerEvent:Connect(remoteController.OnToolActivation)

Players.PlayerRemoving:Connect(function(player)
    if cooldownTable[player.Name] then
        cooldownTable[player.Name] = nil
    end
end)

return remoteController

And this script will add values from tool to player. This specific tool has strenght amount of 2 so it should be supposed to add player leaderstats 2 strenght. If you can help me tnx.

2 answers

Log in to vote
0
Answered by 22 days ago
Edited 22 days ago

Problem

:ClearAllChildren() will clear the children of an instance. If :ClearAllChildren() wasn't a thing, then it would be possibly done like this.

for i, v in ipairs(workspace.Model:GetChildren()) do
   v:Destroy()
end

But that's 3 lines of code, so :ClearAllChildren() is more convenient.

Clearing the children will clear the descendants too.

So, the actual problem is that :ClearAllChildren() only works on instances, but doesn't work on events. I can't help you with the script because I'm not sure what you're trying to do.

You can explain to me what you're trying to do down in the comments and I'll re-edit this answer.

0
Edited post for more info check under -Updated RexPROGaming09 0 — 22d
Ad
Log in to vote
0
Answered by
phxntxsmic 2232 Moderation Voter Community Moderator
21 days ago

Problem

You are trying to use the :ClearAllChildren() method on an RbxScriptSignal.

Solution

:ClearAllChildren() is a method of Instances. RbxScriptSignal is not an Instance.

RbxScriptSignals have 2 methods:

RBXScriptConnection RbxScriptSignal:Connect ( function func )

  • Establishes a function to be called whenever the event is raised.
  • Returns a RBXScriptConnection object associated with the connection.

and

void RBXScriptConnection:Disconnect ( )

  • Yields the current thread until this signal is fired. Returns what was fired to the signal.

As you can see, :ClearAllChildren() is not one of them.

Based on the syntax of "sword.Activated:ClearAllChildren(activated)", it appears you meant to use the :Connect() method instead of :ClearAllChildren().

Code

local replicatedStorage = game:GetService("ReplicatedStorage") 

local Shared = replicatedStorage:WaitForChild("Shared")
local Remotes = Shared:WaitForChild("Remotes") 
local sword = script.Parent 

local function activated() 
    Remotes.On_Tool_Activation:FireServer() 
end 

local function equipped() 
    print("Function_Equipped:Function not finished") 
end

local function unequipped()
    print("Function_Unquipped:Function not finished")
end

sword.Equipped:Connect(equipped)
sword.Unequipped:Connect(unequipped)
sword.Activated:Connect(activated)

Conclusion

If you don't understand something I said, or need help with something else, you can reach me through my Discord server.

Answer this question