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

"string expected, got function" Does anybody know a fix?

Asked by 4 years ago

Hello. I am currently trying to make a local music player. I'm a beginner scripter and have worked around several issues, but this one I'm having trouble with. I get this error message:

ReplicatedStorage.Modules.MusicHandler:47: bad argument #3 (string expected, got function)

And here is my ModuleScript:

local module = {}

-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ContentProvider = game:GetService("ContentProvider")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

-- Variables

local player = Players.LocalPlayer
local musicFrame = player.PlayerGui.MusicPlayer.Frame
local queueBox = musicFrame.Parent.QueueBox
local stopButton = musicFrame.StopButton
local playButtom = musicFrame.PlayButton
local pauseButton = musicFrame.PauseButton
local addButton = musicFrame.AddButton
local skipButton = musicFrame.SkipButton
local repeatButton = musicFrame.RepeatButton
local queueButton = musicFrame.QueueButton
local previousButton = musicFrame.PreviousButton
local idEntry = musicFrame.TextBox
local songNameText = musicFrame.TextLabel
local Sounds = musicFrame.Parent.Sounds
local Music = Sounds.Music

-- Functions

module.findId = (function(id) -- Finds the AssetID for an ID entry
    local id = idEntry.Text
    local assetId = "http://www.roblox.com/asset/?id="..id
    return assetId
end)

module.findSongName = (function(id) -- Finds the Asset name
    local songName = MarketplaceService:GetProductInfo(module.findId)
    return songName
end)

module.addSong = (function() -- Adds a song
    local SongQueue = {}
    table.insert(SongQueue, module.findId)
    for i,v in pairs(SongQueue) do
        local Clone = game.StarterGui.MusicPlayer.QueueBox.TextLabelCloneable:Clone()
        Clone.Position = UDim2.new(0, 0, 0.024 * (i-1), 0)
        Clone.Text = module.findSongName
        Clone.Visible = true
    end
end)

module.openQueue = (function()
    queueBox.Position = UDim2.new(0.816, 0, 0.255, 0)
    if queueBox.Visible == true and queueBox.Active == true and queueBox.ScrollingEnabled == true then
        queueBox.Visible = false
        queueBox.Active = false
        queueBox.ScrollingEnabled = false
    else
        queueBox.Visible = true
        queueBox.Active = true
        queueBox.ScrollingEnabled = true
    end
end)

return module

And here is my LocalScript:

-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ContentProvider = game:GetService("ContentProvider")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

-- Module
MusicHandler = require(game.ReplicatedStorage.Modules.MusicHandler)

-- Variables

local player = Players.LocalPlayer
local musicFrame = player.PlayerGui.MusicPlayer.Frame
local queueBox = musicFrame.Parent.QueueBox
local stopButton = musicFrame.StopButton
local playButtom = musicFrame.PlayButton
local pauseButton = musicFrame.PauseButton
local addButton = musicFrame.AddButton
local skipButton = musicFrame.SkipButton
local repeatButton = musicFrame.RepeatButton
local queueButton = musicFrame.QueueButton
local previousButton = musicFrame.PreviousButton
local idEntry = musicFrame.TextBox
local songNameText = musicFrame.TextLabel
local Sounds = musicFrame.Parent.Sounds
local Music = Sounds.Music
local Click = Sounds.Click

-- Functions
local function onQueueButtonActivated() -- Event for the queue button being clicked
    MusicHandler.openQueue()
    Click:Play()
end

local function onPlayButtonActivated()
    MusicHandler.addSong()
    Click:Play()
end

-- Events
queueButton.MouseButton1Click:Connect(onQueueButtonActivated)
addButton.MouseButton1Click:Connect(onPlayButtonActivated)`

Now, here is where line 47 is in the module (it is marked with --):

module.addSong = (function() -- Adds a song
    local SongQueue = {}
    table.insert(SongQueue, module.findId)
    for i,v in pairs(SongQueue) do
        local Clone = game.StarterGui.MusicPlayer.QueueBox.TextLabelCloneable:Clone()
        Clone.Position = UDim2.new(0, 0, 0.024 * (i-1), 0)
        -- Clone.Text = module.findSongName
        Clone.Visible = true
    end
end)

The purpose of the:

Clone.Text = module.findSongName

is to retrieve what the findSongName returned.

Thanks in advance!

1 answer

Log in to vote
0
Answered by
Psudar 882 Moderation Voter
4 years ago
Edited 4 years ago

Seems you forgot to include the call () operator.

-- try this:

Clone.Text = module.findSongName(id)

You accidentally passed the function itself, instead of what the function returned after calling it, basically.

1
Yes, this fixed it, thanks! Valtonian 43 — 4y
Ad

Answer this question