Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i get a variable to become a string?

Asked by
hozann 75
8 years ago

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

Log in to vote
0
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

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.

0
I'll give it a try :D hozann 75 — 8y
Ad
Log in to vote
1
Answered by 8 years ago

Use:

tostring(Text)

Instead of

toString(Text)

That should fix your issue :)

0
I lose the error, but the decal won't show up, only this will: http://prntscr.com/amxz0i hozann 75 — 8y
0
Instead of using the :Format() function you could use .. (e.g game.Workspace.Decal.Texture = "http://www.roblox.com/asset/?id=" .. assetId legospacepolice 60 — 8y
0
are you sure there's text typed into the TextBox? LightningRoMan 100 — 8y
0
Yeah, i've checked and the asset ID is there, the only problem is now that the decal's 'Texture' wont be changed. hozann 75 — 8y
View all comments (3 more)
0
So i tried it out on a surfacegui, same issue. All it does is add the "http://www.roblox.com/asset/?id=" hozann 75 — 8y
0
At this point, there's nothing we can do. Maybe send us a ROBLOX model to have a look at. LightningRoMan 100 — 8y

Answer this question