Unable to cast string to int64

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I’m Making A Filter System For A TextBox.

  2. What is the issue? It Errors “Unable to cast string to int64”

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? Yes But None Has Same Type.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Server Script:

game.ReplicatedStorage.RemoteEvents.FilterText.OnServerEvent:Connect(function(txt, userid)
	local Filtered = game:GetService("TextService"):FilterStringAsync(txt, userid):GetNonChatStringForBroadcastAsync()
	return Filtered
end)

Local Script:

local txt = script.Parent.InputName.Text
local userid = player.UserId


script.Parent.ChangeName.Activated:Connect(function()
	if script.Parent.InputName.Text ~= "" or " " then
		local Filtered = game.ReplicatedStorage.RemoteEvents.FilterText:FireServer(txt, userid)
		-- workspace.RestarauntSign.RestarauntName.SurfaceGui.TextLabel.Text = Filtered
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

2 Likes

Do print(type(userid)) on the listening side, I assume it’s a string value.

how is that going to help? also ive never used the type() function

it prints saying… “number” ??? how do i fix the filter system tho…

On the ServerScript, make sure you’re passing the player argument even if you don’t plan on using it. (At this point it might actually be better to just use the plr param to get the UserId and not pass in UserId by the way)

game.ReplicatedStorage.RemoteEvents.FilterText.OnServerEvent:Connect(function(plr, txt, userid)

Also if you just define the text of the TextBox there in the LocalScript, if you were to enter text and then fire the remote, it’s going to give you whatever the default text was of that TextBox whenever the script was loaded. I’d recommend defining it as

local txt = script.Parent.InputName

-- then when you're ready to fire the remote, do the following:
 game.ReplicatedStorage.RemoteEvents.FilterText:FireServer(txt.Text, userid)

Also by the looks of your code, it looks like you’re attempting to return a value back from the ServerScript with the RemoteEvent, which actually isn’t possible. Have you considered using a RemoteFunction or something like that instead?

Just gonna jump in and explain why:
The :FireServer() sends the player who called it to the event. This means that .OnServerEvent() will always receive the player as the first argument.

:FireServer() explanation:

Fires the RemoteEvent.OnServerEvent event on the server using the arguments specified with an additional player argument at the beginning.
Source: RemoteEvent (roblox.com)

1 Like

it now is making what i need to use the filtered text say Instance how do i fix

I’m sorry, I don’t quite understand what you are asking. Could you try to describe what exactly is the issue and how that differs from your desired outcome?

when i do the filtered and stuff i make a sign on the workspace say what the filtered is and its now always saying Instance even if the filtered wasnt a swear word

Would you mind showing us your updated script currently?

Local script:

local player = game.Players.LocalPlayer
local txt = script.Parent.InputName


script.Parent.ChangeName.Activated:Connect(function()
	if script.Parent.InputName.Text ~= "" or " " then
		local Filtered = game.ReplicatedStorage.FilterText:InvokeServer(player, txt.Text)
		workspace.RestarauntSign.RestarauntName.SurfaceGui.TextLabel.Text = Filtered
	end
end)

Server Script:

local NpcModule = require(game.ReplicatedStorage.Modules.NpcModule)

function onServerInvoke(plr, txt)
	local Filtered = game:GetService("TextService"):FilterStringAsync(txt, plr.UserId):GetNonChatStringForBroadcastAsync()
	print(Filtered)
	return Filtered
end

game.ReplicatedStorage.FilterText.OnServerInvoke = onServerInvoke

while true do
	wait(math.random(3, 4))
	NpcModule.Spawn()
end

You don’t have to pass player on the local side. Simply do the following for your InvokeServer

local Filtered = game.ReplicatedStorage.FilterText:InvokeServer(txt.Text)

Keep your server side the same, it automatically will do the Player for you. If you want an explanation on why this wasn’t working, essentially because the first variable is automatically player, the player variable you were passing through was actually being your “txt” parameter on the server.

still doesnt filter but fixes the "instance " thing. does the filtering only work on roblox client and not studio?

I don’t believe it works in Studio actually, if you try this in an actual published Roblox place I’m under the assumption it should work. Give it a try and if not we can look into other potential issues. :slight_smile: