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
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.
It can't be in a localScript because of the PointService, or that is what I have been told.