Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I got an Error for my Global Death script ? need help :)

So i got a global death script for my minigame so when a player dies that he wont be in the Game anymore ( like registered ) so the game says "the blabla won" it did all work but now it says that :

Workspace.Globaldeath:5: bad argument #1 to 'Connect' (RBXScriptSignal expected, got function)

here is the script



game:GetService("Players").PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		character:waitForChild("Humanoid").Died.connect(function()
local Update = {}
for i,v in pairs(_G.gameplayers) do
	if v ~= player.Name then
		table.insert(Update,1,v)
		
	end
end		
			
			_G.gameplayers = Update
		end)
	end)
end)

and how can i add that if a player dies he goes into the team "Medium stone grey" ? :) ty

4 comments

0

What is gameplayers also why are you trying to iterate through a function...

0

I got it from the youtuber alvinblox.. Dont understand it ether. and gameplayers are the players who are in the minigame playing

0

Just edited to remove the extra ~

0

I dont know what u mean. I just want to get rid off the Error and i need a fix code thanks

1 answer

✓ Accepted answer

I see your problem now! In line 3 of your posted code, you are supposed to use :Connect(), not .connect(). Also, :connect() is already deprecated, so you MUST get used to that (use :Connect() instead). Now, let me show you the fix:

game:GetService("Players").PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        character:waitForChild("Humanoid").Died:Connect(function() -- Use :Connect()
		local Update = {}
		for i,v in pairs(_G.gameplayers) do
	    		if v ~= player.Name then
	        		table.insert(Update,1,v)
	    		end
		end     
            _G.gameplayers = Update
        end)
    end)
end)

If you have any questions, please leave them in the comments. Thanks!

2 comments

0

By the way, you should try not to use _G because it is not as safe as you imagine. You can just keep it local in the Main Game Script, then use BindableEvents or BindableFunctions to communicate between the death script and the main game script. Use the Roblox Wiki for more info :)

0

thank u very much :) gonna try it out later ^^ I love this site

This discussion is preserved as it was. New answers, comments, and votes are closed.