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

string match expected string got nil??

Asked by 4 years ago
Edited 4 years ago

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 ;'/

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. killerbrenden 1537 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

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

Answer this question