2 SafeZone Commands aren't workings

Hello devs! Im making a safezone commands for safezone pack and my 2 commands aren’t working

first one - rainbow safezone

local rainbow = false
Commands[Rainbow_SafeZone_Command] = function(admin, safezone, value)
	safezone = workspace:FindFirstChild(safezone)
	if safezone then
		local material = safezone.Material
		local color = safezone.Color
		if value == "True" or "true" then
			rainbow = true
			safezone.Material = Enum.Material.Neon
			local pointlight = safezone:FindFirstChild("PointLight") or safezone:FindFirstChildOfClass("PointLight")
			if not pointlight then
				pointlight = Instance.new("PointLight", safezone)
				end
			while safezone do
				task.wait()
				if rainbow == true then
					local hue = tick() % 10/10
					safezone.Color = Color3.fromHSV(hue, 1, 1)
					pointlight.Color = Color3.fromHSV(hue, 1, 1)
					pointlight.Range = 20
					pointlight.Shadows = true
				end
				if safezone.Material ~= Enum.Material.Neon then
					safezone.Material = Enum.Material.Neon
				end
				end
		end
		if value == "False" or "false" then
			rainbow = false
			safezone.Material = material
			safezone.Color = color
			local pointlight = safezone:FindFirstChild("PointLight") or safezone:FindFirstChildOfClass("PointLight")
			if pointlight then
				pointlight:Destroy()
			end
		end
		end
end

This script makes safezone color to rainbow or normal
but if i say false, my safezone changes to rainbow color

Second - Resize safezone command

Commands[Change_SafeZoneSize_Command] = function(admin, safezone, x_size, y_size, z_size)
	safezone = workspace:FindFirstChild(safezone)
	if safezone and typeof(x_size) == "number" and typeof(y_size) == "number" and typeof(z_size) == "number" then
		safezone.Size = Vector3.new(x_size, y_size, z_size)
	end
	if safezone and x_size == "Normal" or y_size == "Normal" or z_size == "Normal" then
		safezone.Size = Vector3.new(31, 28, 38)
	end
end

the goal was resizing the safezone size but it doesnt work anything

First one. You have a while loop which will prevent the rest of the script from completing. So it never checks for the value arg. Move the while loop to the end of the function.
Second. Not sure, I assume it is failing the logic test somehow, try printing typeOf for the x_size etc
You can also specify type in the function arguments like function myFunc(Val : number) it should throw an error then if it gets the wrong type.

1 Like
local rainbow = false

local function Rainbow(safezone, pointlight)
	while safezone do
		task.wait()
		if rainbow == true then
			local hue = tick() % 10/10
			safezone.Color = Color3.fromHSV(hue, 1, 1)
			pointlight.Color = Color3.fromHSV(hue, 1, 1)
			pointlight.Range = 20
			pointlight.Shadows = true
		end
		if safezone.Material == Enum.Material.Neon then
			safezone.Material = Enum.Material.Neon
		end
	end
end

Commands[Rainbow_SafeZone_Command] = function(admin, safezone, value)
	safezone = workspace:FindFirstChild(safezone)
	if safezone then
		local material = safezone.Material
		local color = safezone.Color
		if value == "True" or "true" then
			rainbow = true
			safezone.Material = Enum.Material.Neon
			local pointlight = safezone:FindFirstChild("PointLight") or safezone:FindFirstChildOfClass("PointLight")
			if not pointlight then
				pointlight = Instance.new("PointLight", safezone)
			end
			spawn(Rainbow(safezone, pointlight))
		end
		if value == "False" or "false" then
			rainbow = false
			safezone.Material = material
			safezone.Color = color
			local pointlight = safezone:FindFirstChild("PointLight") or safezone:FindFirstChildOfClass("PointLight")
			if pointlight then
				pointlight:Destory()
			end
		end
		end
end

I made like this but doesnt be fixed

The if logic is a little off.
If value == "True" or value == "true" then
Same with the false line.

1 Like

what should i fix? i cant understand well

This line, checks if the value matches the string or if there is a string, so either way is always true.

1 Like

??? im so srry that im noob i cant understand

but i found something if i delete loop code, everything perfectly works

Interesting. Try adding a longer task.wait(0.3) to the loop, it could just be running too fast to work properly.
Do you not have any errors in output otherwise?

yes there is no error in output + still not be fixed

i fixed first error

blur

Try this for the second problem.

Commands[Change_SafeZoneSize_Command] = function(admin, safezone, x_size, y_size, z_size)
	safezone = workspace:FindFirstChild(safezone)
	if safezone and x_size >= 0 and y_size >= 0 and z_size >= 0 then
		safezone.Size = Vector3.new(x_size, y_size, z_size)
	elseif safezone then
		safezone.Size = Vector3.new(31, 28, 38)
        else
            print("no safezone passed as arg")
	end
end
1 Like

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