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

Why is it not getting a string?

Client Script

local Player = game.Players.LocalPlayer
local Message = script.Parent.Text
game.ReplicatedStorage.SendServer:FireServer(Player, Message)

Server Script

game.ReplicatedStorage.SendServer.OnServerEvent:connect(function(player,msg)
if not LengthCheck(msg) then

function LengthCheck(Message)
if string.len(Message) > 100 then
return false
else
return true
end
end

Error Output-

bad argument #1 to 'len' (string expected, got Object)

2 answers

✓ Accepted answer

When firing a server event, the player (client) who sent the request is already sent to the function. This means our server script is actually getting

function(player, player, message)

You just need to remove 'Player' from :FireServer()

2 comments

0

OMG I Knew I was missing something in front of my face! I'm and Idiot.

0

If this answer helped you and solved your issue, please accept it :)

Your error is that you used the:FireServer method with the Player argument when :FireServer already sends that information as default. This is why string.len spits out an error saying it got an Object instead of a string.

Client

local Player = game.Players.LocalPlayer
local Message = script.Parent.Text
game.ReplicatedStorage.SendServer:FireServer(Message) -- Only needs the message argument

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