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

MarketplaceService:PromptProductPurchase() player should be of type Player, but is of type nil?

hello i have a error that is pretty confusing. i know i wants the player. but i put player in PrompProductPurchase So i Dont Know Whats Going On Please Leave You Suggestions. in The Comments! Error is At 30.

local sirens = game.Workspace.Map.Area47.Siren.Siren2
local Log = script.Parent.YN
local start = script.Parent.Start
local stop = script.Parent.Stop
local stress = game.StarterGui.SeverStress.TextLabel.Value
local MPS = game:GetService("MarketplaceService")
local AirStrikeID = 1082388187
local Players = game:GetService("Players")
local sirenson = false
local Player = Players.LocalPlayer



-- bruv
start.ClickDetector.MouseClick:Connect(function()
	if stress.Value < 90 then
		workspace.bombboi.Launching.Value = "N"
		sirenson = false
		Log.SurfaceGui.TextLabel.TextColor3 = Color3.new(1, 0, 0)
		Log.SurfaceGui.TextLabel.Text = "ERR:STRESS_NOT_ABOVE_90%"
		wait(2)
		Log.SurfaceGui.TextLabel.Text = ""
		Log.SurfaceGui.TextLabel.TextColor3 = Color3.new(1, 1, 1)
	else
		sirens.Sirens.Playing = true
		sirens.Sirens.Volume = 10
		sirenson = true
		Log.SurfaceGui.TextLabel.Text = "Sirens Launched Would You Like To Purchase A Air Strike?"
		wait(1)
		MPS:PromptProductPurchase(Player,AirStrikeID)
		if Enum.ProductPurchaseDecision.PurchaseGranted then
			workspace.bombboi.Launching.Value = "Y"
		else
			Log.SurfaceGui.TextLabel.TextColor3 = Color3.new(1, 0, 0)
			Log.SurfaceGui.TextLabel.Text = "ERR:AIR_STRIKE_NOT_PURCHASED"
			wait(2)
			Log.SurfaceGui.TextLabel.TextColor3 = Color3.new(1, 1, 1)
			Log.SurfaceGui.TextLabel.Text = ""
		     
		end
	end
end)

5 comments

0

Is this a local script?

0

Script

0

Sorry. The Page Got Flooded With New Questions Yesterday

0

Please accept the most helpful answer. There should be an "accept" button to the right.

3 answers

You can't use LocalPlayer in a server script, if you put this in a local script in the same location it should work.

1 comment

0

Still Does Not Work.

You cant use local player in a server script, to get player you need to use player added;

game.Players.PlayerAdded:Connect(function(player)
-- Your code here, player is now a variable for the player
end)

5 comments

0

So you put local player = player ? in there cause i tryed it and it does not work.

0

No, you dont need to define player. Its already passed as a parameter on the function. Are you getting any errors?

0

Make sure you change it to pass player and not Player on line 30.

0

Its Still Giving Me A Red Underline Under player in the gamepass get But If I Put It in A Localscript The Whole Thing Does Not Work

0

Can you edit your thread with your current script?

In a server script you can not use local player, you must detect when a player joins and create a variable. Local player only works in local scripts.

Here is a way to detect a player entering:

game.Players.PlayerAdded:Connect(function(player) -- detects a player joining a creates the variable "player"
-- code
end) -- ends the function

So for you it should be:

local sirens = game.Workspace.Map.Area47.Siren.Siren2
local Log = script.Parent.YN
local start = script.Parent.Start
local stop = script.Parent.Stop
local stress = game.StarterGui.SeverStress.TextLabel.Value
local MPS = game:GetService("MarketplaceService")
local AirStrikeID = 1082388187
local Players = game:GetService("Players")
local sirenson = false


game.Players.PlayerAdded:Connect(function(Player)
start.ClickDetector.MouseClick:Connect(function()
    if stress.Value < 90 then
        workspace.bombboi.Launching.Value = "N"
        sirenson = false
        Log.SurfaceGui.TextLabel.TextColor3 = Color3.new(1, 0, 0)
        Log.SurfaceGui.TextLabel.Text = "ERR:STRESS_NOT_ABOVE_90%"
        wait(2)
        Log.SurfaceGui.TextLabel.Text = ""
        Log.SurfaceGui.TextLabel.TextColor3 = Color3.new(1, 1, 1)
    else
        sirens.Sirens.Playing = true
        sirens.Sirens.Volume = 10
        sirenson = true
        Log.SurfaceGui.TextLabel.Text = "Sirens Launched Would You Like To Purchase A Air Strike?"
        wait(1)
        MPS:PromptProductPurchase(Player,AirStrikeID)
        if Enum.ProductPurchaseDecision.PurchaseGranted then
            workspace.bombboi.Launching.Value = "Y"
        else
            Log.SurfaceGui.TextLabel.TextColor3 = Color3.new(1, 0, 0)
            Log.SurfaceGui.TextLabel.Text = "ERR:AIR_STRIKE_NOT_PURCHASED"
            wait(2)
            Log.SurfaceGui.TextLabel.TextColor3 = Color3.new(1, 1, 1)
            Log.SurfaceGui.TextLabel.Text = ""

        end
    end
end)
end)

ONLY USE BELOW IF YOU ARE USING A GAMEPASS AND NOT A DEVPRODUCT

But... it's not fixed yet, since around April 2018 you can no longer use PromtProductPurchase but now you must use PromtGamePassPurchase

So this should be the complete code:

local sirens = game.Workspace.Map.Area47.Siren.Siren2
local Log = script.Parent.YN
local start = script.Parent.Start
local stop = script.Parent.Stop
local stress = game.StarterGui.SeverStress.TextLabel.Value
local MPS = game:GetService("MarketplaceService")
local AirStrikeID = 1082388187
local Players = game:GetService("Players")
local sirenson = false


game.Players.PlayerAdded:Connect(function(Player)
start.ClickDetector.MouseClick:Connect(function()
    if stress.Value < 90 then
        workspace.bombboi.Launching.Value = "N"
        sirenson = false
        Log.SurfaceGui.TextLabel.TextColor3 = Color3.new(1, 0, 0)
        Log.SurfaceGui.TextLabel.Text = "ERR:STRESS_NOT_ABOVE_90%"
        wait(2)
        Log.SurfaceGui.TextLabel.Text = ""
        Log.SurfaceGui.TextLabel.TextColor3 = Color3.new(1, 1, 1)
    else
        sirens.Sirens.Playing = true
        sirens.Sirens.Volume = 10
        sirenson = true
        Log.SurfaceGui.TextLabel.Text = "Sirens Launched Would You Like To Purchase A Air Strike?"
        wait(1)
        MPS:PromptGamePasstPurchase(Player,AirStrikeID)
        if Enum.GamePasstPurchaseDecision.PurchaseGranted then
            workspace.bombboi.Launching.Value = "Y"
        else
            Log.SurfaceGui.TextLabel.TextColor3 = Color3.new(1, 0, 0)
            Log.SurfaceGui.TextLabel.Text = "ERR:AIR_STRIKE_NOT_PURCHASED"
            wait(2)
            Log.SurfaceGui.TextLabel.TextColor3 = Color3.new(1, 1, 1)
            Log.SurfaceGui.TextLabel.Text = ""

        end
    end
end)
end)

Extra help: Player, GamePassPurchaseFinished, GamePassService

Leave a comment if you need more help or accept the answer if it worked!

1 comment

0

DONT use second code if its not a devproduct and a gamepass

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