Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is it not getting a string?

Asked by
Vezious 310 Moderation Voter
9 years ago

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

Log in to vote
1
Answered by
MrNicNac 855 Moderation Voter
9 years ago

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()

0
OMG I Knew I was missing something in front of my face! I'm and Idiot. Vezious 310 — 9y
0
If this answer helped you and solved your issue, please accept it :) MrNicNac 855 — 9y
Ad
Log in to vote
0
Answered by
4Bros 550 Moderation Voter
9 years ago

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

Answer this question