Hi. I am trying to make a brick that automatically ranks people when they touch it in a group. I am trying to get the players UserId but for that I need LocalPlayer or such to get the userId. I need to use a Server script though for the HTTP or whatever. Man, this auto-ranking system got me all screwed up.
This is my script. I've tried it in both Server and Local scripts.
I honestly have been trying to get this to work for a week now and I don't even know if that's the right URL.
In console it says 'Attempt to index field 'LocalPlayer' (A nil value)
function promouser(gid,rankid,pid) local http = game:getService('HttpService'); local ids = { 'groupId='..gid; 'newRoleSetId='..rankid; 'targetUserId='..pid; }; ids = table.concat(ids,'&'); http:getAsync("https://nameless-bayou-12782.herokuapp.com/"..ids); end; game.Workspace.AutoPromote.Touched:connect (function(hit) promouser(3438171, 23700925, game.Players:GetPlayerFromCharacter(hit.Parent).UserId) print("Promoted to Moderator in Training") end)
Define player from the Touched event.
this should go under line 12.
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
to get the userId, just do player.UserId
The following should replace the current line you have. You can't access the LocalPlayer from the server! This should be the first line in your function, and the function should look something like this:
game.Workspace.AutoPromote.Touched:connect (function(hit) promouser(3438171, 23700925, game.Players:GetPlayerFromCharacter(hit.Parent).UserId) print("Promoted to Moderator in Training") end)