Loadstring() misleading error

Hello! I hope you are having an amazing day!

I am currently working on a building mode for my game. I am creating a scriptable feature, but I keep getting this error:
image


The Code

Client Side:

script.Parent.MouseButton1Click:Connect(function()
	local text = script.Parent.Parent.Box.Text
	game.ReplicatedStorage.RunCode:FireServer(text)
end)

Server Side:

game.ReplicatedStorage.RunCode.OnServerEvent:Connect(function(theCode)
	loadstring(theCode)
end)

LoadStringEnabled = true
image


Solutions I tried

tostring() (Doesn’t make sense since its already a string)


I don’t get why it thinks it is an instance, even though it is a string.

if you can help, please let me know. Thanks! WE

You are getting that error because you are passing a player instance to load string.

The first thing .OnServerEvent returns is the player instance.

You can fix your problem by changing the arguments on the server to player, theCode instead of just theCode

To add on to what @Stratiz said (cause thats literally the answer) I am seeing red flags going off with the system. You are giving clients direct access to the server with this theoretical setup

Don’t worry, I will have security built into the server.

What security are you going to do? They can just delete whatever you have you literally have a server side injector

Completely forgot about that, but now no errors. Nothing is happening when I print Hello World

I am going to use string.find to make sure they can’t do anything horrible.

It’s cause you are serializing the value from its past state u need to do local text = script.Parent.Parent.Parent.Box then do text.Text

Why did I forget Lua all of a sudden lol.

Hmm… Super strange. Still not doing anything…

script.Parent.MouseButton1Click:Connect(function()
	local text = script.Parent.Parent.Box
	game.ReplicatedStorage.RunCode:FireServer(text.Text)
end)

is the code u running that in a local script and are you sure that script.Parent.Parent.Box is the Box you are fielding it to

Yes, it is LocalScript:
image

Maybe there is something wrong with the ServerScript, but I doubt it.

game.ReplicatedStorage.RunCode.OnServerEvent:Connect(function(plr, theCode)
	loadstring(theCode)
end)

If you are playing on the client and print to the server you wont see anything unless you run a play test and switch your window

Wait im confused. Wdym? I added prints before and after everything, and they printed.
image
But not only “Hello World”

Watch do this play your game in actual roblox and do /console and click the server button

Ohhh I get it. Doesn’t work inside of Studio. Thank you for telling me that.
image

Wait, it still doesn’t do anything in regular Roblox…


That Hello World is from another script.

Figured it out. Thanks for the help from everyone.