Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How would I change a SoundID using a textbox entry?

Asked by 6 months ago

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)
0
please refrain from using excessive .Parent climbs. Ziffixture 5654 — 6mo

3 answers

Log in to vote
0
Answered by
Ziffixture 5654 Moderation Voter Community Moderator
6 months ago
Edited 6 months ago

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)
0
Thank you so much!!! It worked Hayz_ll 2 — 6mo
Ad
Log in to vote
3
Answered by
Raccoonyz 893 Donator Moderation Voter
6 months ago

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

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. EpicMetatableMoment 1437 — 6mo
Log in to vote
0
Answered by 6 months ago
Edited 6 months ago

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

Answer this question