Hi!
The title says it all, I need to get the UserID from a ServerScript.
Thanks for and help
Hi!
The title says it all, I need to get the UserID from a ServerScript.
Thanks for and help
game.Players.PlayerAdded:Connect(function(player)
local userid = player.UserId
print("User ID: "…userid) – with two dots not three
end)
Yes, but that’s limiting it to inside the function,
remove the local, it will work
waiting for my friend to test it
What system are you trying to accomplish? From the looks of it, that can be put into the event scope.
local GlitchURL = "https://dorian-horn-verbena.glitch.me/"
function rankUser(UserId, RoleId)
game:GetService("HttpService"):GetAsync(GlitchURL .. "ranker?userid=" .. UserId .. "&rank=" .. RoleId)
end
game.Players.PlayerAdded:Connect(function(player)
UserId = player.UserId
print("User ID: "..UserId)
end)
local RoleId = 10
rankUser(UserId, RoleId)
local MarketplaceService = game:GetService("MarketplaceService")
local Configuration = {
{10133308, 10}
}
game.ReplicatedStorage.ClaimRank.OnServerEvent:Connect(function(Player)
for i = 1, #Configuration do
local GamepassId = Configuration[i][1]
local RankId = Configuration[i][2]
if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
print("Ranked player to " .. RankId)
rankUser(UserId, RankId)
end
end
end)
This is the full code, it’s for a Ranking System
Use a Players | Roblox Creator Documentation event, it’ll return the player that has joined the server.
You can define the player’s userid property at the beginning of your PlayerAdded function if you’d like to.
local Players = game:GetService('Players')
Players.PlayerAdded:Connect(function(player)
local userId = player.UserId
rankUser(userId, 10) -- what it seems like your doing with the screenshot you provided in a reply
end)
Question is why you would need their UserId
in the first place.
In this function you could just replace UserId
with Player.UserId
.
local GlitchURL = "https://dorian-horn-verbena.glitch.me/"
function rankUser(UserId, RoleId)
game:GetService("HttpService"):GetAsync(GlitchURL .. "ranker?userid=" .. UserId .. "&rank=" .. RoleId)
end
game.Players.PlayerAdded:Connect(function(player)
local UserId = player.UserId
print("User ID: "..UserId)
-- this can be placed here
local RoleId = 10
rankUser(UserId, RoleId)
end)
local MarketplaceService = game:GetService("MarketplaceService")
local Configuration = {
{10133308, 10}
}
game.ReplicatedStorage.ClaimRank.OnServerEvent:Connect(function(Player)
for i = 1, #Configuration do
local GamepassId = Configuration[i][1]
local RankId = Configuration[i][2]
if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
print("Ranked player to " .. RankId)
rankUser(Player.UserId, RankId)
end
end
end)
I then get the nil error.
That’s vague. Could you elaborate the error where the argument was nil?