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

Player Identification Help?

Asked by 10 years ago

I have the following script:

local buyButton = game.Workspace.Buttons.BuyButton.SurfaceGui.TextButton
local user = game.Players.LocalPlayer.userId
buyButton.MouseButton1Click:connect(function()
    local productId = 19251902
    Game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, productId)
    local PointsService = Game:GetService("PointsService")
    game.Players.LocalPlayer.leaderstats.Diamonds.Value = game.Players.LocalPlayer.leaderstats.Diamonds.Value + 10
    if  pointsToAward > 0 then
        PointsService:AwardPoints(user, 1)
    end
end

It is in a LocalScript, and Player Points will not be awarded (I know why). I want to move this from a LocalScript to a normal Script. Can I leave LocalPlayer to how it is or do I still need to define him, if so, how?

Thanks, fahmisack123

0
I don't understand how this got a downrate??? fahmisack123 385 — 10y

2 answers

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

LocalPlayer is only defined for LocalScript, because it is not clear (to the server) to whom it refers.

You have to instead reference them some other way. If the LocalScript is a descendant of their player (PlayerGui or PlayerPack tools) or character, then this will just involve invoking the correct number of Parent's and in the case of being in the character, a GetPlayerFromCharacter call.

0
So what would the correct script be, if I want to transfer this script from a LocalScript into a normal Script? fahmisack123 385 — 10y
0
I do not have the necessary context to answer that. It would, however, involve simply substituting some other way to get to the current player for any reference to LocalPlayer. BlueTaslem 18071 — 10y
0
I got an idea, all I need to do is have a new variable. LocalPlayer = what? I need help on this part... fahmisack123 385 — 10y
Ad
Log in to vote
-1
Answered by
lomo0987 250 Moderation Voter
10 years ago

It can't be in a localScript because of the PointService, or that is what I have been told.

0
Said that already. I want to know if this script will work in a normal Script than in a LocalScript. fahmisack123 385 — 10y

Answer this question