Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why wont it print "Test" when value is changed?

when the value "y" its value has been changed, it doesnt print "test". Why wont y.Changed work?

script:

local plr = game.Players.LocalPlayer
local pg = plr:WaitForChild("PlayerGui")

function gameo()
-- Objects

local Life = Instance.new("ScreenGui")
local onelife = Instance.new("ImageLabel")
local secondlife = Instance.new("ImageLabel")
local thirdlife = Instance.new("ImageLabel")
local lifecount = Instance.new("TextLabel")
local y = Instance.new("NumberValue")

-- Properties

Life.Name = "Life"
Life.Parent = game.StarterGui

y.Name = "count"
y.Parent = lifecount

onelife.Name = "onelife"
onelife.Parent = Life
onelife.BackgroundColor3 = Color3.new(1, 1, 1)
onelife.BackgroundTransparency = 1
onelife.Position = UDim2.new(0.551270008, 0, 0, 0)
onelife.Size = UDim2.new(0.0705550313, 0, 0.0990415365, 0)
onelife.Image = "rbxassetid://590924431"

secondlife.Name = "secondlife"
secondlife.Parent = Life
secondlife.BackgroundColor3 = Color3.new(1, 1, 1)
secondlife.BackgroundTransparency = 1
secondlife.Position = UDim2.new(0.621825039, 0, -0.00159744406, 0)
secondlife.Size = UDim2.new(0.0705550313, 0, 0.0990415365, 0)
secondlife.Image = "rbxassetid://590924431"

thirdlife.Name = "thirdlife"
thirdlife.Parent = Life
thirdlife.BackgroundColor3 = Color3.new(1, 1, 1)
thirdlife.BackgroundTransparency = 1
thirdlife.Position = UDim2.new(0.692380071, 0, -0.00159744406, 0)
thirdlife.Size = UDim2.new(0.0705550313, 0, 0.0990415365, 0)
thirdlife.Image = "rbxassetid://590924431"

lifecount.Name = "lifecount"
lifecount.Parent = Life
lifecount.BackgroundColor3 = Color3.new(1, 1, 1)
lifecount.BackgroundTransparency = 1
lifecount.Position = UDim2.new(0.762935102, 0, 0.00958466437, 0)
lifecount.Size = UDim2.new(0, 65, 0, 50)
lifecount.Font = Enum.Font.Arcade
lifecount.Text = "x3"
lifecount.TextColor3 = Color3.new(1, 1, 1)
lifecount.TextScaled = true
lifecount.TextSize = 14
lifecount.TextWrapped = true
y.Value = 3

lifecount.Text = y.Value

y.Changed:Connect(function()
	print("Test")
end)

end

gameo()

thanks

5 comments

0

What causes the value to change, other than y.Value = 3? There's a chance that this won't fire the event

0

changing it thorough the explorer

0

Why are you using global function? You should be using local variables at all tjmes

0

really? everything works except that changed function

0

This looks like a Roblox issue if anything.

1 answer

✓ Accepted answer

Running an event in a function will possibly not make that event work unless you are calling the function in a while true do loop... all you need to do is re-arrange the event and make y a global variable

Look:

local plr = game.Players.LocalPlayer
local pg = plr:WaitForChild("PlayerGui")

function gameo()
-- Objects

local Life = Instance.new("ScreenGui")
local onelife = Instance.new("ImageLabel")
local secondlife = Instance.new("ImageLabel")
local thirdlife = Instance.new("ImageLabel")
local lifecount = Instance.new("TextLabel")
y = Instance.new("NumberValue")  -- I MADE Y GLOBAL, I REMOVED LOCAL

-- Properties

Life.Name = "Life"
Life.Parent = game.StarterGui

y.Name = "count"
y.Parent = lifecount

onelife.Name = "onelife"
onelife.Parent = Life
onelife.BackgroundColor3 = Color3.new(1, 1, 1)
onelife.BackgroundTransparency = 1
onelife.Position = UDim2.new(0.551270008, 0, 0, 0)
onelife.Size = UDim2.new(0.0705550313, 0, 0.0990415365, 0)
onelife.Image = "rbxassetid://590924431"

secondlife.Name = "secondlife"
secondlife.Parent = Life
secondlife.BackgroundColor3 = Color3.new(1, 1, 1)
secondlife.BackgroundTransparency = 1
secondlife.Position = UDim2.new(0.621825039, 0, -0.00159744406, 0)
secondlife.Size = UDim2.new(0.0705550313, 0, 0.0990415365, 0)
secondlife.Image = "rbxassetid://590924431"

thirdlife.Name = "thirdlife"
thirdlife.Parent = Life
thirdlife.BackgroundColor3 = Color3.new(1, 1, 1)
thirdlife.BackgroundTransparency = 1
thirdlife.Position = UDim2.new(0.692380071, 0, -0.00159744406, 0)
thirdlife.Size = UDim2.new(0.0705550313, 0, 0.0990415365, 0)
thirdlife.Image = "rbxassetid://590924431"

lifecount.Name = "lifecount"
lifecount.Parent = Life
lifecount.BackgroundColor3 = Color3.new(1, 1, 1)
lifecount.BackgroundTransparency = 1
lifecount.Position = UDim2.new(0.762935102, 0, 0.00958466437, 0)
lifecount.Size = UDim2.new(0, 65, 0, 50)
lifecount.Font = Enum.Font.Arcade
lifecount.Text = "x3"
lifecount.TextColor3 = Color3.new(1, 1, 1)
lifecount.TextScaled = true
lifecount.TextSize = 14
lifecount.TextWrapped = true
y.Value = 3

lifecount.Text = y.Value


-- THIS IS WHERE THE ORIGINAL CHANGED FUNCTION WAS

end

gameo()
y.Changed:Connect(function()
    print("Test")
end) -- NOW ITS HERE!!! 

So this should print y... If it doesn't, it is probably because the code above wasn't thoroughly checked by me!

If this worked, accept and upvote please Thank you

ps: I also recommend using less global variables..

2 comments

0

it didnt do anything. thanks for helping anyways!

1

I tried.. Functions in functions can sometimes trip up people.. There must be a fault in your code somewhere!!

This discussion is preserved as it was. New answers, comments, and votes are closed.