Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I need a Server script and a Local script at the same time. What do i do?

Asked by 5 years ago
Edited 5 years ago

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)

0
You don't need LocalPlayer because this is not running on the client. T0XN 276 — 5y

2 answers

Log in to vote
0
Answered by
Astralyst 389 Moderation Voter
5 years ago
Edited 5 years ago

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

0
Edit: It says hit is a unknown global error. Another edit: I'm not very intelligent because I put it above 12. :/ Igotthemoney2212 -3 — 5y
0
is it working properly now? Astralyst 389 — 5y
0
No. Attempt to index local 'player' A nil value Igotthemoney2212 -3 — 5y
0
You're calling player before it is defined. Where did you define the player var? T0XN 276 — 5y
0
add "if not player then return end" without quotes below the player declaration Amiaa16 3227 — 5y
Ad
Log in to vote
0
Answered by
T0XN 276 Moderation Voter
5 years ago
Edited 5 years ago

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)
0
Nope. This time it just said 'Line 12. Attempt to index a nil value' I edited my main question code block to what I have now. Igotthemoney2212 -3 — 5y

Answer this question