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

How do i get a variable to become a string?

So, I am basically trying to allow the user with a GUI, add a decal onto a brick, let me clarify that: the decal is already on the brick, and the only issue is translating the variable to a string.

The code is below:

Text = script.Parent.TextBox.Text
assetid = toString(Text)
script.Parent.TextButton.MouseButton1Click:connect(function (onClick)
	game.Workspace.Screen.Decal.Texture = ("http://www.roblox.com/asset/?id=%s"):format(assetid)
	end)

After running this in-game, an error showed up. Here's the image of the error: http:///prntscr.com/amxv49

Would be great if someone could help me out, thanks.

2 answers

✓ Accepted answer

The problem may be that you're initialising the variable 'Text' when the script begins -- not when it's clicked. So, it will be what it was initially, and won't change.

You can fix this by putting it inside of the function:

script.Parent.TextButton.MouseButton1Click:connect(function()
	Text = script.Parent.TextBox.Text
	assetid = tostring(Text)
	game.Workspace.Screen.Decal.Texture = ("http://www.roblox.com/asset/?id=" .. assetid)
end)

Hope this helped.

1 comment

0

I'll give it a try :D

Use:

tostring(Text)

Instead of

toString(Text)

That should fix your issue :)

7 comments

0

I lose the error, but the decal won't show up, only this will: http://prntscr.com/amxz0i

0

Instead of using the :Format() function you could use .. (e.g game.Workspace.Decal.Texture = "http://www.roblox.com/asset/?id=" .. assetId

0

are you sure there's text typed into the TextBox?

0

Yeah, i've checked and the asset ID is there, the only problem is now that the decal's 'Texture' wont be changed.

0

So i tried it out on a surfacegui, same issue. All it does is add the "http://www.roblox.com/asset/?id="

0

At this point, there's nothing we can do. Maybe send us a ROBLOX model to have a look at.

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