Why doesnt this script change the text?

  1. What do you want to achieve? a script that changes the text of the TextLabel to whatever the value of magic is IF the player is a witch

  2. What is the issue? its saying that value is not a valid member of Witch (which is a boolValue)

  3. What solutions have you tried so far? ive tried looking up but nothing useful came up

here’s my script

local player = game.Players.LocalPlayer
local character = player.Character
local witch = character:FindFirstChild("Witch")
local magic = character:FindFirstChild("Magic")
local magicCapacity = character:FindFirstChild("MagicCapacity")
local main = script.Parent.Frame.Main
local MagicGui = script.Parent
local Text = script.Parent.Frame.TextLabel

if witch.Value == true then -- the line it errors on
	MagicGui.Enabled = true
	Text.Text = magic.Value.."/"..magicCapacity.Value
end

all help is appreciated <3

what’s the error in the output?

try it with WaitForChild and see if it work

1 Like

the error says attempt to index nil with 'Value'

in here, can you try WaitForChild()?

Most likely that the value hasn’t replicated to the client yet. Always assume that nothing is there, and you must wait for it to exist. Roblox does not guarantee that anything exists on the client!

Instead of FindFirstChild you should be using WaitForChild, as someone else said.

https://developer.roblox.com/en-us/api-reference/function/Instance/WaitForChild

1 Like