Comfort Mood not working

Hey there! So what I am trying to achieve is a comfort gui that basically increases your comfort level when you sit on the seat, but if your comfort level is too low then you start losing health.


Here is the script:

local plr = game.Players.LocalPlayer
local char = plr.Character
local seat = game.Workspace.Chair.Seat
local fillerUI = script.Parent.FillerUI
local emptyUI = script.Parent.EmptyUI
local time1 = game.Workspace.Time

seat.Changed:Connect(function(Property)
	if Property == "Occupant" then
		if seat.Occupant == char:WaitForChild("Humanoid") then
			for i=fillerUI.Size.X.Offset,100,1 do
				fillerUI.Size = UDim2.new(0,i,0,42)
				time1.Value = i
				script.Parent.TextLabel.Text = time1.Value.."%"
				wait(1)
				if seat.Occupant == nil or time1.Value == 100 then
					break
					end
				
					end
			
				end	
				end
	
	
	if seat.Occupant == nil then
		for i=fillerUI.Size.X.Offset,0,-1 do
			fillerUI.Size = UDim2.new(0,i,0,42)
			time1.Value = i
			script.Parent.TextLabel.Text = time1.Value.."%"
			wait(1)
			if seat.Occupant == char:WaitForChild("Humanoid") then
				break
		end
				end
				end
	end)
	```
1 Like

What about it is not working? a

1 Like

I’m not quite sure how to add the function which lowers player health, I’ve tried this script:

human.Health = human.Health - (human.MaxHealth/4)

Why not just do:

local damage = -- how ever much it is.

humanoid.Health:TakeDamage(damage)

I tested that script but for some reason I received this error:

You would want to use humanoid:TakeDamage(damage) not humanoid.Health:TakeDamage(damage)

1 Like

I’ve tried changing that part of the script but I still got the same error. I think I should create another localscript and do something like this:

local time1 = game.Workspace.Time
local plr = game.Players.LocalPlayer
local char = plr.Character
local humanoid = char:FindFirstChild("Humanoid")

script.Parent:Connect(function(plr)
	if time1.Value = 20 then
		local damage = 20-- how ever much it is.

			humanoid.Health:TakeDamage(damage)
	end
end)

By the way the “Time Value” is a IntValue in the workspace, basically the value that changes according to time.

This won’t work. You did script.Parent:Connect(). There is no event to fire on, it’ll just say 'Connect is not a valid member of (whatever script.Parent.Name is). Also, it’s better to use :GetPropertyChangedSignal() to trigger the seat’s occupant changing.