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?
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!