How to change CollisionGroups with Text or Values

Hello I have a problem where I don’t know what to do. I want to change the collision group of 2 parts using a text.
I have already looked at PhysicsService but it didn’t work either.

Here is an example code how I would like to have it changed:

local gui = script.Parent.GUI.Text
local guider1 = script.Parent.Parent.Parent.Drehgestell1.Guider1
local guider2 = script.Parent.Parent.Parent.Drehgestell1.Guider2


if gui.Text == 21 then
	guider1.CollisionGroup = "R"
	guider2.CollisionGroup = "R"
end
1 Like

Looks like one problem is that you’re trying to check if a string is equal to a number. Either change it to if tonumber(gui.Text) == 21 then or to if gui.Text == "21", otherwise it will always be false since "21" ~= 21.
Other than that, I don’t know exactly what you want to achieve; could you please provide some more detail? Are there any errors in the output? Do you want it to check if the text is equal to “21” whenever it is changed? If so, you’ll need to connect a function to the changed event, like below:

gui:GetPropertyChangedSignal("Text"):Connect(function()
	if gui.Text == 21 then
		guider1.CollisionGroup = "R"
		guider2.CollisionGroup = "R"
	end
end)
1 Like

I wanted to determine the direction in which the guiders can go. R (Right) or default straight ahead. But I got it working now thanks a lot! Here is the script with which it worked:

guider1 = script.Parent.Parent.Parent.Drehgestell1.Guider1
guider2 = script.Parent.Parent.Parent.Drehgestell1.Guider2
gui = script.Parent.GUI.Text

gui:GetPropertyChangedSignal("Text"):Connect(function()
	local guiText = tonumber(gui.Text)

	if guiText == 21 then
		print("TestCollisionGroup")
		guider1.CollisionGroup = "R"
		guider2.CollisionGroup = "R"
	end
end)

2 Likes

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