Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Player Identification Help?

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

1 comment

0

I don't understand how this got a downrate???

2 answers

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.

3 comments

0

So what would the correct script be, if I want to transfer this script from a LocalScript into a normal Script?

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.

0

I got an idea, all I need to do is have a new variable. LocalPlayer = what? I need help on this part...

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

1 comment

0

Said that already. I want to know if this script will work in a normal Script than in a LocalScript.

This discussion is preserved as it was. New answers, comments, and votes are closed.