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

How would I change a SoundID using a textbox entry?

Asked by 4 years 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 6913 — 4y

3 answers

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years 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 — 4y
Ad
Log in to vote
4
Answered by
Raccoonyz 1092 Donator Moderation Voter
4 years 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 1444 — 4y
Log in to vote
0
Answered by 4 years ago
Edited 4 years 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