Checking if a few values has been changed

I’m trying to check if 1 of 3 values has been changed but it doesn’t seem to work and I can’t see any solution so far, I tried to search a solution but couldn’t find. script:

local ReplicatedStorage = game.ReplicatedStorage


local X = ReplicatedStorage.X
local Y = ReplicatedStorage.Y
local Z = ReplicatedStorage.Z

if X.Changed:Connect(function() or Y.Changed:Connect(function() or Z.Changed:Connect(function()
				print("something changed!")
			end)
		end)
	end)
end

This doesn’t work, because the functions are inside of each other. You can’t call a function and another one in the same line. You need to make 3 seperate functions.

Edit:
@Skidouski already sent the correct answer. Make sure to mark his answer as the solution!

2 Likes
local function Changed(Changed)
print(Changed)
end
X.Changed:Connect(function()
Changed("X")
end)
Y.Changed:Connect(function()
Changed("Y")
end)
Z.Changed:Connect(function()
Changed("Z")
end)
2 Likes

Thank you very much, that truly helped me a lot. I’m new to scripting and Trying to program a few games.
Have a nice day!

1 Like

You’re right, I’ve seen it earlier but couldn’t find a way to how to write the connection between these 3 events into a function.

1 Like

Glad to hear that it helped, I also forgot to add that the .Changed event also passes the new value I believe so you could do

local function Changed(Changed, newVal)
print(Changed, newVal)
end
X.Changed:Connect(function(newVal)
Changed("X", newVal)
end)
Y.Changed:Connect(function(newVal)
Changed("Y", newVal)
end)
Z.Changed:Connect(function(newVal)
Changed("Z", newVal)
end)
1 Like

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