local HttpService = game:GetService("HttpService")
game.ReplicatedStorage.Check.OnServerEvent:Connect(function(UserWhoCalled, UserName)
local function status(username, id)
local URL = "https://www.rprxy.xyz/users/"..id.."/profile"
local user = HttpService:GetAsync(URL, true)
if (string.find(user, "icon%-game") ~= nil) then
return "in a game"
elseif (string.find(user, "icon%-online") ~= nil) then
return "online"
else
return "offline"
end
if (string.find(user, "icon%-studio") ~= nil) then
return "in studio"
else
return "offline"
end
end
local URL1 = "https://api.rprxy.xyz/users/get-by-username?username="..UserName -- API that you want to get from
local URL2 = "http://friends.rprxy.xyz/v1/users/"..game.Players:GetUserIdFromNameAsync(UserName).."/friends/count"
local Response = HttpService:GetAsync(URL1)
local Data = HttpService:JSONDecode(Response)
local Response2 = HttpService:GetAsync(URL2)
local Data2 = HttpService:JSONDecode(Response2)
script.Parent.Online.Text = UserName.." is "..status(UserName, game.Players:GetUserIdFromNameAsync(UserName))
script.Parent.ID.Text = "Player ID: "..Data.Id
script.Parent.Username.Text = "Player Username: "..Data.Username
if Data2.count > 1 then
script.Parent.FriendCount.Text = UserName.." has "..Data2.count.." friends."
elseif Data2.count == 0 then
script.Parent.FriendCount.Text = UserName.." has no friends."
end
if Data2.count == 1 then
script.Parent.FriendCount.Text = UserName.." has "..Data2.count.." friend."
end
end)
You do not know how annoying this script has been to me.
I hope that makes sense because I am really stressed because of this script.
As you can see, I am making it return online, offline, in studio or in game BUT THIS STUPID SCRIPT SAYS THIS ERROR:
How can I make it so it stops erroring and shows the player is offline is they are offline?
Somebody please help me, I am litterly feeling like kicking my PC off a cliff right now. Thanks for liking @Liker1
game.ReplicatedStorage.Check.OnServerEvent:Connect(function(UserWhoCalled, UserName)
local function status(username, id)
local URL = "https://www.rprxy.xyz/users/"..id.."/profile"
local user = HttpService:GetAsync(URL, true)
if (string.find(user, "icon%-game") ~= nil) then
return "in a game"
elseif (string.find(user, "icon%-online") ~= nil) then
return "online"
else
return "offline"
end
if (string.find(user, "icon%-studio") ~= nil) then
return "in studio"
else
return "offline"
end
end
end) --Here, to close the OnServerEvent function.
local HttpService = game:GetService("HttpService")
game.ReplicatedStorage.Check.OnServerEvent:Connect(function(UserWhoCalled, UserName)
local function status(username, id)
local URL = "https://www.rprxy.xyz/users/"..id.."/profile"
local user = HttpService:GetAsync(URL, true)
if (string.find(user, "icon%-game") ~= nil) then
return "in a game"
elseif (string.find(user, "icon%-online") ~= nil) then
return "online"
else
return "offline"
end
if (string.find(user, "icon%-studio") ~= nil) then
return "in studio"
else
return "offline"
end
end
end) --Here, to close the OnServerEvent function.
local URL1 = "https://api.rprxy.xyz/users/get-by-username?username="..UserName -- API that you want to get from
local URL2 = "http://friends.rprxy.xyz/v1/users/"..game.Players:GetUserIdFromNameAsync(UserName).."/friends/count"
local Response = HttpService:GetAsync(URL1)
local Data = HttpService:JSONDecode(Response)
local Response2 = HttpService:GetAsync(URL2)
local Data2 = HttpService:JSONDecode(Response2)
script.Parent.Online.Text = UserName.." is "..status(UserName, game.Players:GetUserIdFromNameAsync(UserName))
script.Parent.ID.Text = "Player ID: "..Data.Id
script.Parent.Username.Text = "Player Username: "..Data.Username
if Data2.count > 1 then
script.Parent.FriendCount.Text = UserName.." has "..Data2.count.." friends."
elseif Data2.count == 0 then
script.Parent.FriendCount.Text = UserName.." has no friends."
end
if Data2.count == 1 then
script.Parent.FriendCount.Text = UserName.." has "..Data2.count.." friend."
end
end)
Oh my bad, ignore my first post. I think I found it:
local function status(username, id)
local URL = "https://www.rprxy.xyz/users/"..id.."/profile"
local user = HttpService:GetAsync(URL, true)
if (string.find(user, "icon%-game") ~= nil) then
return "in a game"
elseif (string.find(user, "icon%-online") ~= nil) then
return "online"
else
return "offline"
end
In this part, the function would be returned no matter what the outcome is. If they are in a game, it would return. If they are online, it would return. If they are offline, it would return. Meaning that the code below it would never be executed. You can solve this by using a variable instead:
game.ReplicatedStorage.Check.OnServerEvent:Connect(function(UserWhoCalled, UserName)
local playerStatus --Your new variable.
local function status(username, id)
local URL = "https://www.rprxy.xyz/users/"..id.."/profile"
local user = HttpService:GetAsync(URL, true)
if (string.find(user, "icon%-game") ~= nil) then
playerStatus = "in a game"
elseif (string.find(user, "icon%-online") ~= nil) then
playerStatus = "online"
else
playerStatus = "offline"
end
if (string.find(user, "icon%-studio") ~= nil) then
playerStatus = "in studio"
else
playerStatus = "offline"
end
end
--The rest of the code.
I think this should be it… sorry for not reading it the first time round haha.
I don’t think that has anything to do with the script’s error then. You should add a print() below them, if it prints offline too then it would probably be a mistake in retrieving information from the API. That would not be an API error but perhaps you can retrieve it differently? I haven’t used APIs in awhile so I will see what I can find.
None of it is my script, it’s all yours. I only fixed the error which you requested to be fixed. I did not touch any of the HTTP requests - but I am pretty bored so I will experiment around with it too and tell you what I can get.
Thanks to @MrOofBoyPlayz for sharing the model with me in DMs! The problem has been resolved, but just in case anybody runs into this in the future, I will share it here too.
local function status(username, id)
local URL = "https://www.rprxy.xyz/users/"..id.."/profile"
local user = HttpService:GetAsync(URL, true)
if (string.find(user, "icon%-game") ~= nil) then
playerStatus = "in a game"
elseif (string.find(user, "icon%-online") ~= nil) then
playerStatus = "online"
else
playerStatus = "offline"
end
if (string.find(user, "icon%-studio") ~= nil) then
playerStatus = "in studio"
else
playerStatus = "offline"
end
end
In this function, the if statement at the end would check if the player is in Studio. If they are not, it would always revert to offline. It can be fixed by running through all of the possible statuses in a desired order:
local function status(username, id)
local URL = "https://www.rprxy.xyz/users/"..id.."/profile"
local user = HttpService:GetAsync(URL, true)
if (string.find(user, "icon%-game") ~= nil) then
playerStatus = "in a game"
elseif (string.find(user, "icon%-online") ~= nil) then
playerStatus = "online"
elseif (string.find(user, "icon%-studio") ~= nil) then
playerStatus = "in Studio"
else
playerStatus = "offline"
end
end
And intially, the function would be returned no matter what the outcome is. If they are in a game, it would return. If they are online, it would return. If they are offline, it would return. Meaning that the code below it would never be executed.