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

Why isn't the output responding to the input correctly?

The script is part of a gui to buy something called bonds. I'm having a problem with (input which is script.Parent.Text) and (output which is script.Parent.Parent.HowManyResult.Text). when I put in a number in the script.Parent.Text, the number goes to script.Parent.Parent.InputVal.Value which is multiplied by bondprice to get the cost of however many bonds you want. However many bonds you want are only limited by the maximum amount of bonds which makes the maximum price. The bondprice.Value is 7. the output is supposed to be the bondprice.Value times the script.Parent.Parent.InputVal.Value and the problem is that the output isn't the input value * 7. If I wanted 1 bond the output would be 0 and it's supposed to be 7, that's the problem. Can someone help me, thank you. The script is below.

--// Edited for code block. In the future please be sure to enclose your code between two lines of tildes (~), which can be inserted by clicking the blue button under the title of the question editor.

local theinput = script.Parent.Parent.InputVal
local player = game.Players.LocalPlayer

script.Parent.Changed:connect(function()
	

local bondprice = game.Lighting.Bank.Price.BondPrice
local maximumshares = math.floor(player.PlayerMoney.Value/bondprice.Value)
local maximumprice = math.floor(maximumshares*bondprice.Value)


local n = tonumber(script.Parent.Text)
if (not n) then return end


if theinput.Value > maximumshares then
script.Parent.Parent.HowManyResult.Text = "$" .. maximumprice
elseif theinput.Value < maximumshares then
	script.Parent.Parent.HowManyResult.Text = "$" .. theinput.Value * bondprice.Value
end




end)

while wait(0.01) do 
theinput.Value = script.Parent.Text
end

1 comment

0

Please put your code in a code block so it is easier for us to read.

1 answer

✓ Accepted answer

I believe your code is getting stuck in your while loop

local theinput = script.Parent.Parent.InputVal
local player = game.Players.LocalPlayer

function changed() --I changed the code you had into a function that we will call when the script.Parent changes

local bondprice = game.Lighting.Bank.Price.BondPrice
local maximumshares = math.floor(player.PlayerMoney.Value/bondprice.Value)
local maximumprice = math.floor(maximumshares*bondprice.Value)


local n = tonumber(script.Parent.Text)
if (not n) then return end


if theinput.Value > maximumshares then
script.Parent.Parent.HowManyResult.Text = "$" .. maximumprice
elseif theinput.Value < maximumshares then
    script.Parent.Parent.HowManyResult.Text = "$" .. theinput.Value * bondprice.Value
end

end

game:GetService("RunService").RenderStepped:connect(funtion() -- Since this is in a localscript we can use RenderStepped from RunService check and update every frame that is rendered.
theinput.Value = script.Parent.Text
changed(); -- We are calling the function here to see if it changes.
end)

I hope this helped. If it did please accept this as the answer. If it didn't feel free to comment so I can try to help and figure out why it isn't working.

8 comments

0

On line 25, it says in parentheses "changed" there is no function named changed, what do I do?

0

Oh I see the problem sorry. xD I changed my code to fix it

0

When I put in a value it still doesnt work.

0

Can you set the place you have to a team create and invite me?

0

Omg thank you so much, I was fiddling around with it. How do I make this forum answered thank you so much I'm so happy it spent 2 days doing this.

0

Glad I could help. xD The Accept Answer button is below the post a comment bar,

0

I cant find it :/

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