I changed the bit circled from demote to rank in case it was calling the wrong AppURL but nothing happened with either. I get why it says demote instead of rank and have fixed that but do you have any ideas what could be going wrong with the functionality?
It says “Unknown global “Data””. Also when testing the command will it work in Studio or shall I connect to the public place and try ranking my alt? But yes it says that data is unknown.
local HttpService = game:GetService("HttpService")
local ReplicatedStorage = game.ReplicatedStorage
local AppUrl = script.AppUrl.Value
local ApiKey = script.ApiKey.Value
local Groupid = script.GroupId.Value
local MinRank = script.MinRank.Value
local prefix = "!"
local function FindPlr(plr)
local foundPlr = nil
local plrs = game.Players:GetPlayers()
for i = 1, #plrs do
local current = plrs[i]
if string.lower(current.Name):sub(1, #plr) == string.lower(plr) then
foundPlr = current.Name
break
end
end
return foundPlr
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
if player:GetRankInGroup(Groupid) >= 2 then
local LowerCaseMessage = string.lower(msg)
if string.find(LowerCaseMessage, "!promote") then
local SplitMessage = string.split(msg, " ")
local full_player = FindPlr(SplitMessage[2])
if full_player == nil then
local playerInstance = game.Players:FindFirstChild(player.Name)
game.ReplicatedStorage.Notify:FireClient(playerInstance, "Uh-Oh","We couldn't find the player you wanted to promote!")
else
local playerInstance = game.Players:FindFirstChild(player.Name)
game.ReplicatedStorage.Notify:FireClient(playerInstance, "Attempting.","Attempting to promote user...")
local Url = script.AppUrl.Value.."group/promote?user_name="..full_player.."&key=" ..script.ApiKey.Value.."&groupid="..script.GroupId.Value
local success, response = pcall(function()
local response = HttpService:GetAsync(Url)
local data = HttpService:JSONDecode(response)
end)
if success then
game.ReplicatedStorage.Notify:FireClient(playerInstance, "Horrah!","We promoteed the user!")
else
game.ReplicatedStorage.Notify:FireClient(playerInstance, "Uh-Oh","We had problems promoting the user.")
end
end
else if string.find(LowerCaseMessage, "!demote") then
local SplitMessage = string.split(msg, " ")
local full_player = FindPlr(SplitMessage[2])
if full_player == nil then
local playerInstance = game.Players:FindFirstChild(player.Name)
game.ReplicatedStorage.Notify:FireClient(playerInstance, "Uh-Oh","We couldn't find the player you wanted to demote!")
else
local playerInstance = game.Players:FindFirstChild(player.Name)
game.ReplicatedStorage.Notify:FireClient(playerInstance, "Attempting.","Attempting to demote user...")
local Url = script.AppUrl.Value.."group/demote?user_name="..full_player.. "&key=" ..script.ApiKey.Value.. "&groupid=" ..script.GroupId.Value
local success, response = pcall(function()
local response = HttpService:GetAsync(Url)
local data = HttpService:JSONDecode(response)
end)
if success then
game.ReplicatedStorage.Notify:FireClient(playerInstance, "Horrah!","We demoted the user!")
else
game.ReplicatedStorage.Notify:FireClient(playerInstance, "Uh-Oh","We had problems demoting. the user.")
end
end
else if string.find(LowerCaseMessage, "!rank") then --Look for the rank command to be used
local SplitMessage = string.split(msg, " ") --Split the message
local full_player = FindPlr(SplitMessage[2]) --Get the 2nd word in the message
local req_rank = SplitMessage[3]
--Get the 3rd word in the message
if full_player == nil then
local playerInstance = game.Players:FindFirstChild(player.Name) --Get the player that sent the command.
game.ReplicatedStorage.Notify:FireClient(playerInstance, "Uh-Oh","We couldn't find the player you wanted to rank!") --Notify the client that it failed.
else --if player exsists
local playerInstance = game.Players:FindFirstChild(player.Name) --Find player that sent command.
game.ReplicatedStorage.Notify:FireClient(playerInstance, "Attempting.","Attempting to rank user...") --Send loading.
local Url = script.AppUrl.Value.."group/rank?user_name="..full_player.. "&key=" ..script.ApiKey.Value.. "&groupid=" ..script.GroupId.Value.. "&role_number=" ..req_rank --Add RoleNumber To The Data sent to the WebServer.
local success, response = pcall(function(data) --Pcall for obvious reasons
local response = HttpService:GetAsync(Url) --Send request to webserver
local data = HttpService:JSONDecode(response) --Decode Json Data.
end)
if success then --test if worked.
game.ReplicatedStorage.Notify:FireClient(playerInstance, "Horrah!","We changed the rank of the user the user!") --Custom edited the error messages.
else
game.ReplicatedStorage.Notify:FireClient(playerInstance, "Uh-Oh","We had problems changing the rank of the user.") --Custom edited the error messages.
end
end
end
end
end
end
end)
end)
Please mark this post as solution, also please double check I haven’t made a typo .