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

(line 87) Expected string, got userdata? but that is a string!

Asked by 5 years ago

I'm trying to make a message command for when you say lib.cmds:msg.hi and it'd say "[lib] hi" but instead it errors out. Please help!

01-- Made by iiDk
02-- Settings
03local version = "1"
04local plr = owner -- aka iiDkOffical, i like owner more lol
05-- Functions
06local function message(text) -- Sends a message to the server
07local msg = Instance.new("Message")
08msg.Parent = game:GetService("Workspace")
09msg.Text = text
10wait(3)
11msg:Destroy()
12end
13local function playSound(soundCat,soundName,soundId,musicId) -- Plays a sound
14 local sound = Instance.new("Sound")
15 sound.SoundId = "rbxassetid://"..soundId
View all 99 lines...

2 answers

Log in to vote
1
Answered by 5 years ago

You are setting msg to a new instance on line 85, so it is not a string by the time it gets to line 87.

0
no i'm trying to set the message of it iiDkOffical 109 — 5y
1
By setting msg=Instance.new("Message"), you overwrite the string that it used to be. On line 87, you call string.sub(msg,14), but you just set msg to something that is not a string, so it wont work. IStarConquestI 414 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

To manipulate any string, you need to make sure it's actually a string. You said it is but if you go back to that line, the message is an instance so if you try to "sub" an instance, it won't work.

I think you forgot to do msg.Text but instead you did msg alone.

To fix it, change this line in Line 87:

1msg.Text = "[lib] "..string.sub(msg,14)

To this

1msg.Text = "[lib] "..string.sub(msg.Text,14)

Answer this question