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

String returns as a table?

The script is returning a table instead of a string. What am i doing wrong?

module script:

local Ask = {}

Ask.Bind = Instance.new("BindableFunction")

function Ask.Prompt(Question)
	if game.Players.LocalPlayer.PlayerGui:FindFirstChild("AskUI") then
		game.Players.LocalPlayer.PlayerGui.AskUI:Destroy()
	end
	
	ui = script.AskUI:Clone()

	ui.Ask.TextLabel.Text = Question --<<this turns the text into a table somehow>>--
	script.Woosh:Play()
	ui.Parent = game.Players.LocalPlayer.PlayerGui
	ui.Ask:TweenPosition(UDim2.new(0.392, 0,-0.06, 0), "Out", "Back", script.Woosh.TimeLength, false)

	ui.Ask.No.MouseButton1Click:Connect(function()
		Ask.Bind:Invoke("No")
		script.Woosh:Play()
		ui.Ask:TweenPosition(UDim2.new(0.392, 0,-0.192, 0), "In", "Back", script.Woosh.TimeLength, false)
		wait(script.Woosh.TimeLength)
		ui:Destroy()
	end)
	ui.Ask.Yes.MouseButton1Click:Connect(function()
		Ask.Bind:Invoke("Yes")
		script.Woosh:Play()
		ui.Ask:TweenPosition(UDim2.new(0.392, 0,-0.192, 0), "In", "Back", script.Woosh.TimeLength, false)
		wait(script.Woosh.TimeLength)
		ui:Destroy()
	end)
end

return Ask

local script:

local ask = require(game.ReplicatedFirst.LocalModules.Ask)

ask.Bind.OnInvoke = function(returned)
	if returned == "Yes" then
		print("Yes")
	elseif returned == "No" then
		print("No")
	end
end

ask:Prompt("Test") --<<here is the problem>>--

3 comments

0

what exactly is "Test" being turned into

0

Calling a modular function with : will return the first argument as self. You need to account for that in your modules function like you would with calling a remote from the client and getting its player back as the first argument... function Ask.Prompt(Self, Question)

1

or, you could just replace the ":" with "." at line 11 of your LocalScript to call the function without passing the first argument as "self" (as it would if the function were a method that you call with ":")

1 answer

Comments already explained, but I'll put it in clear terms:

ask:Prompt("Test") is syntatical sugar for ask.Prompt(ask, "Test") What you believe to be a string turned into a table is actually just thr ask table itself. Change the : to a . to fix.

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