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

Attempt to concatenate instance with string?

Asked by 3 years ago

Hello there! I'm currently having trouble with my morph into player script. The main handler throws an error: attempt to concatenate instance with string.

Here is the remote function code:

local remoteFunction = game.ReplicatedStorage:FindFirstChild("requestPlayerStatus")
local HttpProxy = require(game.ServerScriptService.HttpProxyService:Clone())

    remoteFunction.OnServerInvoke = function(Id)
    local data = game.HttpService:JSONEncode(HttpProxy:GetAsync("http://api.roblox.com/users/" .. Id .. "/onlinestatus"))
    if not data.IsOnline then
        return "offline"
    end
    if data.IsOnline then
        return "online"
    end
end

The GUI local script code:

local plrStatus = game.ReplicatedStorage.requestPlayerStatus:InvokeServer(script.Parent.Parent.Parent.UserId.Value)

if plrStatus == "offline" then
    script.Parent.TextColor3 = Color3.fromRGB(85, 255, 0)
    script.Parent.Text = "Online"
end

if not plrStatus == "offline" then
    script.Parent.TextColor3 = Color3.fromRGB(255, 0, 0)
    script.Parent.Text = "Offline"
end

I've looked through every devforum post mentioning this error. I apply the solution to my code unfortunately it does not change anything and still throws an error. I've tried everything I could possibly thing of. tostring() didn't work. tonumber() didn't work. I have absolutely no idea how to troubleshoot my code.

Any ideas?

0
onserverinvoke returns the player as one of the arguments. JesseSong 3916 — 3y
0
try id.Name JesseSong 3916 — 3y
0
don't forget to accept the answer if it helped you. JesseSong 3916 — 3y

1 answer

Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
3 years ago

The problem is that you're attempting to concatenate a string with a player (an instance). This will not work and will result in an error since you can't do that. A simple solution would be on line 5, add id.Name. This function gets the player's username, and will fix your issue!

0
Well I'm using it as a player info for a morph. The Id will be inputted by the player. Oliver_Bocch 32 — 3y
0
It throws this error when I try what you said: http://api.roblox.com/users/Oliver_Bocch/onlinestatus failed to fetch because Unable to fetch Oliver_Bocch 32 — 3y
0
send a snapshot of the error JesseSong 3916 — 3y
0
this should work. send a pic of the code that i told you to edit JesseSong 3916 — 3y
View all comments (4 more)
0
did you try: local data = game.HttpService:JSONEncode(HttpProxy:GetAsync("http://api.roblox.com/users/" .. Id .Name.. "/onlinestatus")) JesseSong 3916 — 3y
0
replace line 5 JesseSong 3916 — 3y
0
let me know if you have more enquiries, comments. JesseSong 3916 — 3y
Ad

Answer this question