CDNDEV
(CDNDEV)
February 28, 2021, 1:20am
#1
Hello Developers, I am currently trying to achieve a discord webhook system that logs time spent in game for a certain group rank and above.
Currently the issue I am facing is that it works fully but it is not locking the rank.
It is also logging guests and other ranks that are not stated in the ranking section.
What I am stuck on is how to fix the script so that it will properly show only the rank I state and higher.
Example of script error on webhook data ( Check mark is correct logging )
SCRIPT:
local groupID = 9283240
local rankNeeded = 3
sendData = function(color, msg, title, url, footer)
local httpService = game:GetService(“HttpService”)
local urlData = “webhook hidden for privacy”
if footer then
footer = {
[‘text’] = footer;
};
end
local data = httpService:JSONEncode({
[‘username’] = “Shift Handler”;
[‘embeds’] = {{
[‘title’] = title;
[‘url’] = url;
[‘description’] = msg;
[‘footer’] = footer;
[‘color’] = color;
}};
})
httpService:PostAsync(urlData, data)
end
game:GetService(“Players”).PlayerAdded:Connect(function(player)
if (player:GetRankInGroup(groupID) >= rankNeeded) then
ct = tick()
print(‘player joined’)`
I just need to figure out how to fix the rank id so that it only logs rank 3 - 255 of group 9283240
And so it will not log any other ranks or non group members.
Xacima
(Yui)
February 28, 2021, 1:58am
#2
Where’s your PlayerRemoving event?
Full code please, I cannot help you without seeing everything.
CDNDEV
(CDNDEV)
February 28, 2021, 2:31am
#3
local rankNeeded = 3
sendData = function(color, msg, title, url, footer)
local httpService = game:GetService("HttpService")
local urlData = "hidden for privacy"
if footer then
footer = {
['text'] = footer;
};
end
local data = httpService:JSONEncode({
['username'] = "Shift Handler";
['embeds'] = {{
['title'] = title;
['url'] = url;
['description'] = msg;
['footer'] = footer;
['color'] = color;
}};
})
httpService:PostAsync(urlData, data)
end
game:GetService("Players").PlayerAdded:Connect(function(player)
if (player:GetRankInGroup(groupID) >= rankNeeded) then
ct = tick()
print('player joined')
sendData(65280, player.Name.." ("..player.UserId..") | "..player:GetRoleInGroup(groupID).." has started a shift", "Shift Started", ("https://www.roblox.com/users/%s/profile"):format(player.UserId), "Halifax Regional Police")
end
end)
game:GetService("Players").PlayerRemoving:Connect(function(player)
local timelasted = math.ceil(tick()-ct)
sendData(16711680, player.Name.." ("..player.UserId..") | "..player:GetRoleInGroup(groupID).." has ended a shift "..(timelasted/60).." minutes of activity.", "Shift Ended", ("https://www.roblox.com/users/%s/profile"):format(player.UserId), "Halifax Regional Police")
end)
CDNDEV
(CDNDEV)
February 28, 2021, 2:32am
#4
I accidentally missed the group id at the top. but its the same as above. Thats just the rest of the script.
Xacima
(Yui)
February 28, 2021, 2:33am
#5
That’s because you don’t check what their rank is when leaving.
You can create a connection for the ranked players by doing this:
if Rank >= DesiredRank then
Players.PlayerRemoving:Connect(function()
-- Code.
end)
end
CDNDEV
(CDNDEV)
February 28, 2021, 3:28am
#6
So where you said Code. Is where I put the information.
So the code should look like this?
if Rank >= 3 then
Players.PlayerRemoving:Connect(function()
local groupID = 9283240
local rankNeeded = 3
sendData = function(color, msg, title, url, footer)
local httpService = game:GetService("HttpService")
local urlData = "webhook link"
if footer then
footer = {
['text'] = footer;
};
end
local data = httpService:JSONEncode({
['username'] = "Shift Handler";
['embeds'] = {{
['title'] = title;
['url'] = url;
['description'] = msg;
['footer'] = footer;
['color'] = color;
}};
})
httpService:PostAsync(urlData, data)
end
game:GetService("Players").PlayerAdded:Connect(function(player)
if (player:GetRankInGroup(groupID) >= rankNeeded) then
ct = tick()
print('player joined')
sendData(65280, player.Name.." ("..player.UserId..") | "..player:GetRoleInGroup(groupID).." has started a shift", "Shift Started", ("https://www.roblox.com/users/%s/profile"):format(player.UserId), "Halifax Regional Police")
end
end)
game:GetService("Players").PlayerRemoving:Connect(function(player)
local timelasted = math.ceil(tick()-ct)
sendData(16711680, player.Name.." ("..player.UserId..") | "..player:GetRoleInGroup(groupID).." has ended a shift "..(timelasted/60).." minutes of activity.", "Shift Ended", ("https://www.roblox.com/users/%s/profile"):format(player.UserId), "Halifax Regional Police")
end)
end)
end
MrNicNac
(nox7)
February 28, 2021, 4:08am
#8
Sorry, I’m confused. You’re checking the rank in the group in the PlayerAdded - but not PlayerRemoving?
kylerzong
(kylerzong)
February 28, 2021, 4:19am
#9
local GroupID = 9283240
local RankNeeded = 3
local webHookUrl = ""
local function FormatSeconds(Seconds) return string.format("%2ih, %2im, %2is", Seconds/60^2, Seconds/60%60, Seconds%60) end
local JoinData = {}
game.Players.PlayerAdded:Connect(function(Player)
JoinData[Player.UserId] = tick()
if Player:GetRankInGroup(GroupID) >= RankNeeded then
local webHookData =
{
["content"] = "",
["username"] = "Shift Log",
["embeds"] = {{
["title"] = "** Shift Started **",
["type"] = "rich",
["color"] = tonumber(0xff0c0c),
["fields"] = {
{
["name"] = "Player",
["value"] = "Username: "..Player.Name.."\nUser ID: "..tostring(Player.UserId).."\nRole: "..Player:GetRoleInGroup(GroupID),
["inline"] = false
},
{
["name"] = "Server",
["value"] = "Job ID: "..game.JobId.."\nPlayers: "..#game.Players:GetPlayers().."\nUptime: "..FormatSeconds(time()),
["inline"] = false
}
}
}}
}
game:GetService("HttpService"):PostAsync(webHookUrl, game:GetService("HttpService"):JSONEncode(webHookData))
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local PlayerJoinTick = JoinData[Player.UserId]
JoinData[Player.UserId] = nil
if Player:GetRankInGroup(GroupID) >= RankNeeded then
local webHookData =
{
["content"] = "",
["username"] = "Shift Log",
["embeds"] = {{
["title"] = "** Shift Ended **",
["type"] = "rich",
["color"] = tonumber(0xff0c0c),
["fields"] = {
{
["name"] = "Player",
["value"] = "Username: "..Player.Name.."\nUser ID: "..tostring(Player.UserId).."\nRole: "..Player:GetRoleInGroup(GroupID),
["inline"] = false
}, {
["name"] = "Time Spent",
["value"] = FormatSeconds(tick() - PlayerJoinTick),
["inline"] = false
},
{
["name"] = "Server",
["value"] = "Job ID: "..game.JobId.."\nPlayers: "..#game.Players:GetPlayers().."\nUptime: "..FormatSeconds(time()),
["inline"] = false
}
}
}}
}
game:GetService("HttpService"):PostAsync(webHookUrl, game:GetService("HttpService"):JSONEncode(webHookData))
end
end)
Xacima
(Yui)
February 28, 2021, 6:36am
#10
The code should look like the example I provided. You simply add your request inside the PlayerRemoving event I pre-made for you.
What this is doing is basically only allowing players that pass that if statement to have that event be fired when they leave, which is better than checking it again once some random player leave that doesn’t meet this requirement.
Good luck, I hope this clears up your confusion.
local rankNeeded = 3
sendData = function(color, msg, title, url, footer)
local httpService = game:GetService("HttpService")
local urlData = "hidden for privacy"
if footer then
footer = {
['text'] = footer;
};
end
local data = httpService:JSONEncode({
['username'] = "Shift Handler";
['embeds'] = {{
['title'] = title;
['url'] = url;
['description'] = msg;
['footer'] = footer;
['color'] = color;
}};
})
httpService:PostAsync(urlData, data)
end
game:GetService("Players").PlayerAdded:Connect(function(player)
if (player:GetRankInGroup(groupID) >= rankNeeded) then
ct = tick()
print('player joined')
sendData(65280, player.Name.." ("..player.UserId..") | "..player:GetRoleInGroup(groupID).." has started a shift", "Shift Started", ("https://www.roblox.com/users/%s/profile"):format(player.UserId), "Halifax Regional Police")
end
end)
game:GetService("Players").PlayerRemoving:Connect(function(player)
if (player:GetRankInGroup(groupID) >= rankNeeded) then
local timelasted = math.ceil(tick()-ct)
sendData(16711680, player.Name.." ("..player.UserId..") | "..player:GetRoleInGroup(groupID).." has ended a shift "..(timelasted/60).." minutes of activity.", "Shift Ended", ("https://www.roblox.com/users/%s/profile"):format(player.UserId), "Halifax Regional Police")
end
end)