How do i make properties for multiple objects(Transparency, anchored and etc.)

  1. What do you want to achieve? Keep it simple and clear!
    I wanna acces multiple object properties in few lines of code
  2. What is the issue? Include screenshots / videos if possible!
    No idea how to do that
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tryed to add a big variable which contains every object, but didn’t help.

My code:

local Player = game.Players.LocalPlayer
local ChristmasStartedValue = Player.PlayerGui.ChristmasGUI.Frame.EventStarted
local GiftPack = game.Workspace.Gifts
local GiftN = {
	GiftPack.Gift1, GiftPack.Gift2, GiftPack.Gift3,
	GiftPack.Gift4, GiftPack.Gift5, GiftPack.Gift6,
	GiftPack.Gift7, GiftPack.Gift8, GiftPack.Gift9,
	GiftPack.Gift10, GiftPack.Gift11, GiftPack.Gift12,
	GiftPack.Gift13, GiftPack.Gift14, GiftPack.Gift15,
	GiftPack.Gift16,
}

while true do
	if ChristmasStartedValue.Value == "False" then
		GiftN.Transparency = 1
		GiftN.CanCollide = false
	end
	if ChristmasStartedValue.Value == "True" then
		GiftN.Transparency = 0
		GiftN.CanCollide = true
	end
wait(0.5)	
end

3 Likes

Try looping through everything inside the GiftN table like this:

local Player = game.Players.LocalPlayer
local ChristmasStartedValue = Player.PlayerGui.ChristmasGUI.Frame.EventStarted
local GiftPack = game.Workspace.Gifts
local GiftN = {
	GiftPack.Gift1, GiftPack.Gift2, GiftPack.Gift3,
	GiftPack.Gift4, GiftPack.Gift5, GiftPack.Gift6,
	GiftPack.Gift7, GiftPack.Gift8, GiftPack.Gift9,
	GiftPack.Gift10, GiftPack.Gift11, GiftPack.Gift12,
	GiftPack.Gift13, GiftPack.Gift14, GiftPack.Gift15,
	GiftPack.Gift16,
}

while true do
	if ChristmasStartedValue.Value == "False" then
		for _, GiftNs in pairs(GiftN) do
			GiftN.Transparency = 1
			GiftN.CanCollide = false
		end
	end
	if ChristmasStartedValue.Value == "True" then
		for _, GiftNs in pairs(GiftN) do
			GiftNs.Transparency = 0
			GiftNs.CanCollide = true
		end
	end
	task.wait(0.5)	
end
2 Likes

image
no this don’t work(P.S Gift must be invisible)

Is ChristmasStartedValue a boolean?

1 Like

+1 for using for loops as a simple solution

1 Like

No it is string value
image

You should use a BoolValue as it can only return true/false.

1 Like

Okay lemme test that, thanks you

Oh also, the True would turn into true and the False would turn into false, please note that capitalization changes.

1 Like

In the script, when you are changing the value, make sure the true/false is ONLY in lowercase, otherwise the script may through an error. Make sure to remove the quotes around the value as well.

1 Like

image
Still

is the True and False still a string?

2 Likes

I do not change value, i getting a value. If false … if true …

Yes it is

local Player = game.Players.LocalPlayer
local ChristmasStartedValue = Player.PlayerGui.ChristmasGUI.Frame.EventStarted
local GiftPack = game.Workspace.Gifts
local GiftN = {
	GiftPack.Gift1, GiftPack.Gift2, GiftPack.Gift3,
	GiftPack.Gift4, GiftPack.Gift5, GiftPack.Gift6,
	GiftPack.Gift7, GiftPack.Gift8, GiftPack.Gift9,
	GiftPack.Gift10, GiftPack.Gift11, GiftPack.Gift12,
	GiftPack.Gift13, GiftPack.Gift14, GiftPack.Gift15,
	GiftPack.Gift16,
}

while true do
	if ChristmasStartedValue.Value == "False" then
		for _, GiftNs in pairs(GiftN) do
			GiftN.Transparency = 1
			GiftN.CanCollide = false
		end
	end
	if ChristmasStartedValue.Value == "True" then
		for _, GiftNs in pairs(GiftN) do
			GiftNs.Transparency = 0
			GiftNs.CanCollide = true
		end
	end
	task.wait(0.5)	
end

You need to remove the ' around the true/false and put them in lowercase

1 Like

change the “True” and “False” to true and false

1 Like

oh and remove the quotes

Summary

This text will be hidden

1 Like

image
Right?

1 Like

The script would now be:

local Player = game.Players.LocalPlayer
local ChristmasStartedValue = Player.PlayerGui.ChristmasGUI.Frame.EventStarted
local GiftPack = game.Workspace.Gifts
local GiftN = {
	GiftPack.Gift1, GiftPack.Gift2, GiftPack.Gift3,
	GiftPack.Gift4, GiftPack.Gift5, GiftPack.Gift6,
	GiftPack.Gift7, GiftPack.Gift8, GiftPack.Gift9,
	GiftPack.Gift10, GiftPack.Gift11, GiftPack.Gift12,
	GiftPack.Gift13, GiftPack.Gift14, GiftPack.Gift15,
	GiftPack.Gift16,
}

while true do
	if ChristmasStartedValue.Value == false then
		for _, GiftNs in pairs(GiftN) do
			GiftN.Transparency = 1
			GiftN.CanCollide = false
		end
	end
	if ChristmasStartedValue.Value == true then
		for _, GiftNs in pairs(GiftN) do
			GiftNs.Transparency = 0
			GiftNs.CanCollide = true
		end
	end
	task.wait(0.5)	
end

also credit to: BriefTaste

2 Likes