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

How would I change a SoundID using a textbox entry?

So I have a GUI in which a player can enter their sound ID for it to change the sound of the horn. However, it isn't working and is only changing the sound ID to the "rbxassetid://" part and doesn't include what the user entered. Here is my script:

repeat wait() until script:FindFirstAncestorOfClass("PlayerGui")
local player = script:FindFirstAncestorOfClass("Player").Name
local userboat = script.Parent.Parent.Parent.Ship.Value
local seat = userboat.VehicleSeat
local musicID = script.Parent.Parent.TextBox.Text

script.Parent.MouseButton1Click:Connect(function()
	print("submitted sound")
	seat.Horn.SoundId = "rbxassetid://" .. musicID
	print("sound submitted")
end)

1 comment

0

please refrain from using excessive .Parent climbs.

3 answers

✓ Accepted answer

Your issue is the fact that you declared musicID as a constant; meaning that it will capture the state of which it was in after immediately being loaded, and will not reconfigure to any new input. Instead, you should capture the Text upon the MouseButton1Click signal:

--// Ensure this is a LocalScript within the GUI
local TextBoxInput = script:FindFirstAncestorOfClass("TextBox")
local Button = script.Parent

local Seat = script:FindFirstAncestor("Ship").Value.VehicleSeat
--// This pathway is redundant, please reformat

Button.MouseButton1Click:Connect(function()
    local SoundID = tonumber(TextBoxInput.Text)
    Seat.Horn.SoundId = "rbxassetid://"..SoundID
end)

1 comment

0

Thank you so much!!! It worked

Server scripts cannot obtain info from TextBoxes. You'll need to use RemoteFunctions and a LocalScript to do this.

1 comment

0

I suggest using a remote event in this case because it looks like the player submits a value rather than the server requesting one.

Edited

repeat wait() until script:FindFirstAncestorOfClass("PlayerGui")
local player = script:FindFirstAncestorOfClass("Player").Name
local userboat = script.Parent.Parent.Parent.Ship.Value
local seat = userboat.VehicleSeat


script.Parent.MouseButton1Click:Connect(function()
    local musicID = script.Parent.Parent.TextBox.Text
    print("submitted sound")
    seat.Horn.SoundId = "rbxassetid://"..musicID -- You put spaces here
    print("New horn sound ID: "..musicID)
end)

If this helped please accept this answer.

All the best,

PrismaticFruits

1 comment

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