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
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)
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)