Script can't interact with the UI

So I’m making a blood system using Knit where the player loses blood every second. The system itself works fine; however, making a simple UI bar that tracks the amount of blood the player has seems impossible. When I try to change the visibility, text color, or text of the bar and its children, nothing happens, and I don’t get any errors in the output.

Here is my BloodController script:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Knit = require(ReplicatedStorage.Packages.knit)

local BloodBarController = Knit.CreateController({
	Name = "BloodBarController",
})

function BloodBarController:KnitStart()
	local BloodService = Knit.GetService("BloodService")
	local localPlayer = Players.LocalPlayer

	-- Wait for PlayerGui
	local playerGui = localPlayer:WaitForChild("PlayerGui")
	local bloodGui = playerGui:WaitForChild("BloodGui")
	local background = bloodGui:WaitForChild("Background")
	local bar = background:WaitForChild("Bar")
	local percentLabel = bar:WaitForChild("Percent") -- This should now exist

	BloodService.ShowBarUI:Connect(function(state)
		background.Visible = state
		print("Changing Visible State Of Blood Bar (" .. tostring(state) .. ")")
	end)

	BloodService.SetBloodUI:Connect(function(percent)
		print("Changed Amount Of Blood (" .. percent .. ")")
		bar.Size = UDim2.new(percent / 100, 0, 1, 0)

		if tonumber(percent) <= 25 then
			percentLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
		else
			percentLabel.TextColor3 = Color3.fromRGB(255, 0, 0)
		end
		percentLabel.Text = tostring(percent)
	end)
end

return BloodBarController

In the output here’s what i get :


As you can see, the BloodControllernow if he needs to hide or show the bar and how much blood the player has but he don’t interact with the UI

Here is the UI:

1 Like

Hi, your script works just fine in my test, i have an idea why it may not work to you, can you please tell what happens when you run the game step by step?

Hello!

Is your script a LocalScript? Most people know this but UI only works with LocalScripts. I’m assumIng you are using a LocalScript. And where is the script being stored?

BloobertTheGoob :wink:

ok my bad i used a module script in replicated storage

1 Like