Attempt to call a RBXScriptConnection value

So thats my code and the error is in the title but I don’t know how to fix it

local PhysicService = game:GetService("PhysicsService")

local PlayersGroup = "Players"

PhysicService:CollisionGroupSetCollidable(PlayersGroup, PlayersGroup, false)

local function TurnOffCharacterCollisions(character)
	local allChildren = character:GetDescendants()
	for i = 1, #allChildren do
		local limb = allChildren[i]
		if limb:IsA("BasePart") then
			limb.CollisionGroup = "Players"
		end
	end
end

for i,v in ipairs(workspace.Dummys:GetChildren()) do
	TurnOffCharacterCollisions(v)
end

workspace.Dummys.ChildAdded:Connect(function(Player)
	TurnOffCharacterCollisions(Player)
end)

local function character_added(character)
	character.AncestryChanged:wait()
	game:GetService("RunService").Stepped:wait()
	character.Parent = game.Workspace.Dummys
end

game:GetService("Players").PlayerAdded:Connect(function(player)
	local character = player.Character or player.CharacterAdded:Wait()
	player.CharacterAdded:Connect(character_added)(character) --error
end)
1 Like
player.CharacterAdded:Connect(function(character)
    character_added(character)
end)

In this corrected version, the character_added function is wrapped in an anonymous function, which is then connected to the CharacterAdded event. This way, when the CharacterAdded event is triggered, it will call the character_added function with the character as an argument.

it works now thx but it only works after the character died once so when they join the first time they arent in the “Dummys” folder like they should

Try this:

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(character_added)
end)

Also inside your character_added function you could try to directly call TurnOffCharacterCollisions

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.