Creating a Temperature System

Hello, y’all. I’m a new member here. I’m working on the temperature system, if you touch the cold area, it will repeatedly decrease your temperature or If you touch the hot area, it will repeatedly increase the temperature. And I’m using ZonePlus which it is really useful! and I’m trying to create a script in Server. Not in (LocalScript)Client to avoid the exploits/hacks.

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Zone = require(ReplicatedStorage.Zone)
local ZoneController = require(ReplicatedStorage.Zone.ZoneController)


local ancestorContainer = workspace.ZoneTemp

local Temperature = {}

Players.PlayerAdded:Connect(function(player)
	local temp = Instance.new("NumberValue")
	temp.Parent = player
	temp.Name = "Temperature"
	temp.Value = 10
	Temperature[player] = temp
	print(Temperature)
	
	player.CharacterRemoving:Connect(function()
		temp.Value = 10
	end)
end)

Players.PlayerRemoving:Connect(function(player)
	Temperature = nil
end)

local function CreateZone(container)
	local customZone = Zone.new(container)
	customZone:bindToGroup("EnterOnlyOneZoneAtATime")
	local HWC = 0
	customZone.playerEntered:Connect(function()
		if customZone.Name == "Cold" then
			HWC = 1
		elseif customZone.Name == "Hot" then
			HWC = 2
		elseif customZone.Name == "Warm" then
			HWC = 3
		end
		print(HWC)
	end)

	customZone.playerExited:Connect(function()
	end)


	local connection

	local function DestroyZone()
		customZone:unbindFromGroup("EnterOnlyOneZoneAtATime")
		customZone:destroy()

		connection:Disconnect()
		connection = nil
	end

	connection = container.AncestryChanged:Connect(function()
		if container.Parent ~= ancestorContainer then
			DestroyZone()
		end
	end)

	container.Destroying:Connect(DestroyZone)
end


for _, container in ipairs(ancestorContainer:GetChildren()) do
	CreateZone(container)
end

ancestorContainer.ChildAdded:Connect(CreateZone)


--local function WhileTrueDo()
--	while true do
--		task.wait(3)
		
--	end
--end

https://gyazo.com/c8d06f0cb38f832e5215828f0c7a9276

I’m struggling with this part where it’s not changing the value “HWC” HWC is short for “HotWarmCold”

1 Like

You’re sure the customZone has a name? Only thing I can think of that could be wrong.

Oh, I recently checked it. Whoops. My mistaken. It’s supposed to be container.

1 Like

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