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

string match expected string got nil??

nights = {[1] = "monster1",[2] = "monster2"}

Client

game.ReplicatedStorage.start:FireServer(v.Name)

Server

game.ReplicatedStorage.start.OnServerEvent:Connect(function(n)
for i,model in pairs(game.ServerStorage:GetChildren()) do 
if string.match(nights[tonumber(n)],v.Name) then 
model:Clone().Parent = workspace
end 
end
end)

output

 ServerScriptService.send:61: bad argument #1 to 'match' (string expected, got nil)

Basically the client is sending a object's name, The server is going through the table and seeing if the string matches with any children in server storage If there's a easier way to do this please tell me, This is really confusing ;'/

1 comment

0

n, is the name of an object right? You are trying to turn that name (String) into a Integer (Number), and you cannot do that, you can turn Integers into Strings, but not vice versa. Unless, that name of the object is 1 or 2.

1 answer

✓ Accepted answer

change server code to this

game.ReplicatedStorage.start.OnServerEvent:Connect(function(player,n)
for i,model in pairs(game.ServerStorage:GetChildren()) do 
if string.match(nights[tonumber(n)],v.Name) then 
model:Clone().Parent = workspace
end 
end
end)

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