LocalWE
(WilliApple)
March 29, 2021, 5:07am
#1
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:
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
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
Stratiz
(Stratiz)
March 29, 2021, 5:11am
#2
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
1 Like
CoderHusk
(CoderHusk)
March 29, 2021, 5:12am
#3
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
LocalWE
(WilliApple)
March 29, 2021, 5:13am
#4
Don’t worry, I will have security built into the server.
CoderHusk
(CoderHusk)
March 29, 2021, 5:13am
#5
What security are you going to do? They can just delete whatever you have you literally have a server side injector
LocalWE
(WilliApple)
March 29, 2021, 5:13am
#6
Completely forgot about that, but now no errors. Nothing is happening when I print Hello World
LocalWE
(WilliApple)
March 29, 2021, 5:14am
#7
I am going to use string.find
to make sure they can’t do anything horrible.
CoderHusk
(CoderHusk)
March 29, 2021, 5:14am
#8
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
LocalWE
(WilliApple)
March 29, 2021, 5:14am
#9
Why did I forget Lua all of a sudden lol.
LocalWE
(WilliApple)
March 29, 2021, 5:16am
#10
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)
CoderHusk
(CoderHusk)
March 29, 2021, 5:18am
#11
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
LocalWE
(WilliApple)
March 29, 2021, 5:18am
#12
Yes, it is LocalScript:
Maybe there is something wrong with the ServerScript, but I doubt it.
game.ReplicatedStorage.RunCode.OnServerEvent:Connect(function(plr, theCode)
loadstring(theCode)
end)
CoderHusk
(CoderHusk)
March 29, 2021, 5:19am
#13
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
LocalWE
(WilliApple)
March 29, 2021, 5:24am
#14
Wait im confused. Wdym? I added prints before and after everything, and they printed.
But not only “Hello World”
CoderHusk
(CoderHusk)
March 29, 2021, 5:25am
#15
Watch do this play your game in actual roblox and do /console and click the server button
LocalWE
(WilliApple)
March 29, 2021, 5:27am
#16
Ohhh I get it. Doesn’t work inside of Studio. Thank you for telling me that.
LocalWE
(WilliApple)
March 29, 2021, 5:31am
#17
Wait, it still doesn’t do anything in regular Roblox…
LocalWE
(WilliApple)
March 29, 2021, 5:34am
#18
That Hello World is from another script.
LocalWE
(WilliApple)
March 29, 2021, 5:46am
#19
Figured it out. Thanks for the help from everyone.