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

Error Message that says That keeps saying "attempt to index local 'Player' (a nil value)?"

19:59:01.025 - ServerScriptService.2x Gamepass:4: attempt to index local 'Player' (a nil value)

local Player = game.Players.LocalPlayer

local id = 6634524
local ClickBonus = Player.WaitForChild("playerstats").ClickBonus

game:GetService("MarketplaceService").PromptGamePassPurchaseFinished.Connect(function(plr,ido,purchased)
	if purchased and id == ido then
		ClickBonus.Value = ClickBonus.Value * 2	
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.user,id) then
		ClickBonus.Value = ClickBonus.Value * 2
	end
end)

Can any one tell me how to fix this

1 answer

The server can't find player using LocalPlayer.

But the event is return plr to us.

Also you use Connect as :Connect(

Also WaitForChild is used with :

Also.. userid is gotten from players using .UserId

local id = 6634524

game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
    if purchased and id == ido then
	local ClickBonus = plr:WaitForChild("playerstats").ClickBonus
        ClickBonus.Value = ClickBonus.Value * 2 
    end
end)

game.Players.PlayerAdded:Connect(function(plr)
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId,id) then
	local ClickBonus = plr:WaitForChild("playerstats").ClickBonus
        ClickBonus.Value = ClickBonus.Value * 2
    end
end)

8 comments

0

20:43:30.483 - ServerScriptService.2x Gamepass:3: bad argument #1 to 'Connect' (RBXScriptSignal expected, got function) now i have that

0

@Jasonemefele edited answer

0

user is not a valid member of Player

0

@Jasonemefele updated again

0

@Jasonemefele Make sure to accept the answer if it helped.

0

ServerScriptService.2x Gamepass:12: attempt to index global 'ClickBonus' (a nil value)

0

@Jasonemefele Updated againn

0

ServerScriptService.2x Gamepass:2: attempt to index global 'plr' (a nil value)

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