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

Attempt to concatenate instance with string?

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?

3 comments

0

onserverinvoke returns the player as one of the arguments.

0

try id.Name

0

don't forget to accept the answer if it helped you.

1 answer

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!

8 comments

0

Well I'm using it as a player info for a morph. The Id will be inputted by the player.

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

0

send a snapshot of the error

0

this should work. send a pic of the code that i told you to edit

0

did you try: local data = game.HttpService:JSONEncode(HttpProxy:GetAsync("http://api.roblox.com/users/" .. Id .Name.. "/onlinestatus"))

0

replace line 5

0

let me know if you have more enquiries, comments.

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