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

How do i use remote events smart so i don't need to create five instead of only one?

Asked by 4 years ago

So i created a music gui, and when u click a play button its going to play, but on the server. so when u click on the play button, then its going to fire a event, and its going to play and everybody can hear it, but what if i then want so if the player click pause and it fires the same event. its just going to play the song again. if that makes sense.

Client script

local RE = game.ReplicatedStorage:WaitForChild("RemoteEvent")
script.Parent.Play.MouseButton1Click:Connect(function()
    if script.Parent.TextBox.TextBox.Text ~= "" then 
    local Plr = game.Players.LocalPlayer
    local Asset = game.MarketplaceService:GetProductInfo(script.Parent.TextBox.TextBox.Text)
    script.Parent.SongName.Text = Asset.Name
    script.Parent.UploadedBy.Text = "Uploaded by "..Asset.Creator.Name
    RE:FireServer("rbxassetid://"..script.Parent.TextBox.TextBox.Text,"Play")
    end
end)
script.Parent.Pause.MouseButton1Click:Connect(function()
RE:FireServer("rbxassetid://"..script.Parent.TextBox.TextBox.Text,"Pause")
end)
script.parent.Stop.MouseButton1Click:Connect(function()
    RE:FireServer("rbxassetid://"..script.Parent.TextBox.TextBox.Text,"Stop")
    script.Parent.SongName.Text = ""
    script.parent.UploadedBy.Text = "Uploaded by nobody"
    script.Parent.TextBox.TextBox.Text = ""
end)

Server script

local RE =game.ReplicatedStorage:WaitForChild("RemoteEvent")
RE.OnServerEvent:Connect(function(sender, ID,Gen)
    if Gen == "Play" then
    local Character = sender.Character
    if not Character:FindFirstChild("Sound") then
    local Sound = Instance.new("Sound",Character)
    Sound.SoundId = ID
    Sound.Looped = true
    Sound:Play()
    end
    if Gen == "Pause"then
    Character:FindFirstChild("Sound")
    end
    if Gen == "Stop" then
    Character:FindFirstChild("Sound"):Destroy()

    end
    end
end)

u can see i tried with the if gen == "Play" then but it dosn't work

1 answer

Log in to vote
0
Answered by
cegberry 432 Moderation Voter
4 years ago

Are you sure you have written out your full script? If yes, then...

    if Gen == "Pause"then
    Character:FindFirstChild("Sound")
    end

You'd add in :Pause() to pause the music:

    if Gen == "Pause"then
    Character:FindFirstChild("Sound"):Pause()
    end
0
Still dosn't work and it were because i edited the script and must have forgot that but still dosn't work dr6g0nb0y 27 — 4y
0
are you using the old sound script, where it's a server script named "Sound", located in your character? if so then this is the problem, "if not Character:FindFirstChild("Sound") then" cegberry 432 — 4y
Ad

Answer this question