Unable to find a character to use in a function (No Error)

The whole of the script works except the part which finds the character. I have searched the internet but I cannot find what I need.

Here is the script:

local ps = game:GetService("PhysicsService")
ps:CreateCollisionGroup("fiftyPointdoor")
ps:CreateCollisionGroup("50Pointplayer")

local fiftyPdoor = game.Workspace.fiftyPdoor

local function SetColGroupDoors(door, group)
	ps:SetPartCollisionGroup(door, group)
end

SetColGroupDoors(fiftyPdoor, "fiftyPointdoor")

local function SetColGroupPlr(char, group)
	for i, child in ipairs(char:GetChildren()) do
		if child:IsA("BasePart") then
			ps:SetPartCollisionGroup(child, group)
		end
	end
	char.DescendantAdded:Connect(function(desc)
		if desc:IsA("BasePart") then
			ps:SetPartCollisionGroup(desc, group)
		end
	end)
end

game.Players.PlayerAdded:Connect(function(plr)--Error somewhere here
	plr.CharacterAdded:Connect(function(char)
		while true do
			wait(1)
			if plr.leaderstats.Points.Value >= 50 then
				SetColGroupPlr(char, "50Pointplayer")
			end
		end
	end)
end)

ps:CollisionGroupSetCollidable("fiftyPointdoor", "50Pointplayer", false)

Thanks for reading and I hope you can help!

1 Like

did u checked twice the player.leaderstats.points.value?

1 Like

look at the title of the post, it says there (in other words no, there was no error)

1 Like

if u mean check its the right variable, then yes it is

do a print of it before your loop β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž

1 Like

yeah maybe there is inf loop that causing a issue

1 Like

What environment is changing the value of Points? In the client or server?
And while I assume this is a server-side script, I’d like to be sure. What is the class name/script context of this script?

the print works! the problem is in the loop

Make sure that leaderstats is avaiable and the Points value is updated before trying to access it.

Since i currently don;t have the points system working, I have just been using the command bar to give myself points

If you’re running the command bar in the client, only the client can see the changes. Switch to the server environment and try the code there.

Unfortunately this doesn’t seem to be the problem

You mean you are running this script in command bar? Or that you are increasing the points of yours from command bar?

If you increase the points in command bar client side, then that value will never change on server side, go to server side in your simulation and increase the points from there, but. Even if you increase the points there, your script wont do nothing cause it will only fire when player joins. So if a player already joined and you change the points after the join your script will do nothing

I thought it being in a while true do would solve that issue when I made the code. Can you explain how to fix this?

I think we have a misunderstanding. Your while loop probably is correctly checking the value if exist, otherwise you would see a error.

But if you are changing the value from client side your while loop will never find that the points are higher or equal to 50 so, it will never call to SetColGroupPlr()

Add a print on that function to see if that function is at least called

The function is called, i have tried changing the points server side and nothing changed.

What exactly is not changing?

I mean what is the behavior you expect to happen?
In that function you are asking parts of the player be added to a collision group.
You dont see the parts added into that Collision group? or what is the sympthom?

I expect the player to not collide with the door

So you said the function got called correctly, you added prints to see that each part of the player got added during the for loop?

You actually did check the collision group tab to see what parts are in it?
Perhaps the door is not even in that collision group, but if you check whats into that collision group you would find a reason why its not working

Jut checked, it seems both have been added to their collision group. The issue seems to be in making them not collide with eachother.