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

I need help?

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I need help, could you explain to me how I would create a script, that will change your swords textureID, from mesh, when you type an ID from decals into a GUI bar, and could you explain to me how to make this happen when you press "Enter", after you have typed in the ID?

2 answers

Log in to vote
1
Answered by 10 years ago

Assuming the script is in the mesh:

script.Parent.TextureId = "http://www.roblox.com/asset/?id=PUT_ID_HERE"

As for the second one, I don't really understand... press Enter while holding a tool? Only if a specific player does it? While standing on it? Please explain further.

0
No, it's a GUI Bar, where if you type something, and press enter it will insert it into the ID. Lem0nzz 5 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Let's assume you have the gui bar (TextBox) ready at your disposal. To change the texture you would make the gui bar (TextBox) check to see when you have entered something in it and then you want to make it change the TextureId of the sword. Probably with something along the lines of:

local Texture = GuiBar.Text
local SwordMesh = script.Parent
pcall(function()
    SwordMesh.TextureId = "http://www.roblox.com/asset/?id=" .. Texture
end)

With this we are assuming your TextBox is GuiBar and that the parent of the script is the mesh you are changing. This code should be placed within the part where the script has checked and realised that your TextBox' text has changed, which we will get onto when I start explaining the next bit of your question. As you can see from this, Texture is the text of GuiBar, which we are assuming is your TextBox, and SwordMesh is the mesh. We are using a pcall (protected function) just in case SwordMesh isn't actually a mesh. We then change the TextureId of the mesh to the roblox link to fetch assets, with the text of GuiBar concatenated onto the end.

Now onto the second part of your question, making it detect you pressing enter. I could have gone into a long tutorial about using KeyDown and then using ASCII for the enter key, but luckily for you roblox have got an event just for this purpose. The event is "FocusLost" and it is used to detect when you previously were typing something in the TextBox, but have now finished and thus the focus on the TextBox has been lost. We would probably use it in this case like this:

local SwordMesh = script.Parent
GuiBar.FocusLost:connect(function(Enter)
    if Enter then
        pcall(function()
            local Texture = GuiBar.Text
            SwordMesh.TextureId = "http://www.roblox.com/asset/?id=" .. Texture
        end)
    end
end)

As you can see, FocusLost checks to see if Enter has been pressed with the argument "Enter". If Enter has been pressed then it runs the code previously supplied by me, except in this we have already set SwordMesh so that we don't have to set it every time. If you want it to be allowed so that it can also be executed by the player clicking off of the TextBox, then just remove the line where it checks if enter has been pressed, and the corresponding end. So, this is how I would do it, I hope you enjoyed my tutorial.

Answer this question