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

Please help me solve why this script isn't working i got no answer last time?

I created this script but it doesn't work, it's a VIP door. Don't know what I'm doing wrong but any and all help would be greatly appreciated, thanks. This is in a regular script inside a block.

local ID = 1369781260
plr = game.Players.LocalPlayer

debounce=false

function onTouched(hit)
	if debounce==true then return end
	debounce=true
	
      
    game:GetService("MarketplaceService"):PromptPurchase(plr, ID)

	
	debounce=false

end

script.Parent.Touched:connect(onTouched)


8 comments

0

Is there a error in the logs?

0

No

0

Then I can not help you

0

Well thanks man. You sure tried.

0

I found out using print commands it doesn't get passed this command.... game:GetService("MarketplaceService"):PromptPurchase(plr, ID)

0

15:03:25.054 - MarketplaceService:PromptPurchase() player should be of type Player, but is of type nil. -----Tat's the error.

0

You cannot use LocalPlayer in a regular script.

0

I put it all in a local script and now it doesn't work at all

2 answers

✓ Accepted answer
local ID = 1369781260
debounce=false

function onTouched(hit)
    if debounce==true then return end
        debounce=true
        local plr = game.Players:WaitForChild(hit.Parent
Name)

        game:GetService("MarketplaceService"):PromptPurchase(plr, ID)

        debounce=false
    end
end

script.Parent.Touched:connect(onTouched)

10 comments

0

Try that. ^

0

No errors but i don't know if it's working because i added print commands in the beginning, middle, and end and didn't read any of them...

0

Can you tell me where the script is located and put a print at every stage of the script including before the touched event?

0

The script is located inside a part. It is a local script.

0

Make it a serverscript please.

0

It doesn't get past this.... local plr = game.Players:WaitForChild(hit.ParentName)

0

Please keep helping.

0

Use GetPlayerFromCharacter.

0

Or just add a dot between Parent.Name

0

Thank you so much i added the dot and fixed it. It works perfectly now

Roblox's GamePass service likes to act stupid. try this script.

local ID = 1369781260
debounce=false
local market = game:GetService("MarketplaceService")
local pass = game:GetService("GamePassService")

function onTouched(hit)
    if debounce ~= true then
	debounce = true
	if hit.Name ~= "Handle" then
        local plr = game.Players:WaitForChild(hit.Parent.Name)
		if not pass:PlayerHasPass(plr, ID) then
			market:PromptPurchase(plr , ID)
		end
	else
		local plr = game.Players:WaitForChild(hit.Parent.Parent.Name)
		if not pass:PlayerHasPass(plr, ID) then
			market:PromptPurchase(plr , ID)
		end
	end
		debounce=false
	end
end

script.Parent.Touched:connect(onTouched)

if it doesn't work, let me know. Also, sometimes the part hits the player's hair before it hits the actual body, so I added in a workaround for that as well.

5 comments

0

That is the most ridiculously overly complicated script I have ever seen.

0

It's not that complicated if you actually read it. Also, I've made many scripts that are more complicated.

0

No errors but the script doesn't work. It doesn't pull up the product that i have for sale.

0

I put it in a server side script not a local.

0

That's weird. It works on my computer. I even put it into a published game to test it on roblox and it still worked.

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