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

I'm confused, when I try to make a x2 coin pass it complains about the end, but I don't know why?

I'm having troubles making a coin that gives extra if you own a game pass such as a x2 coin pass. I have tried to edit this, by placing a if you own gamepass if, else thing here:


local id = 6488475 -- your gamepass id

local db = true
script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		if db == true then
			db = false
			script.Parent.Transparency = 1
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			local extra = 2 -- always add 1 extra to this such as if it gives +2 instead of 1, dont put 1, put 2.
			player.CharacterAdded:connect(function(char)
		    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(game.Players[char.Name].UserId, id) then
			player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + extra
-- etc

I did put a else afterwards and other stuff so. i just didn't put it up here. I'm trying to help my buddy out, and this would be useful to me to. ill put in the game pass id later of course. I have attempted to do this, i'm having troubles with the end not working. Here is the end part, i have done my best but a error still comes up:

end)

		end
		
end)

I assume this is due to a incorrect if and else error or misplaced character or even a missing line that it needs. Please help me find the error, and fix it. Not trying to request.

2 answers

✓ Accepted answer
local id = 6488475 -- your gamepass id

local db = true
script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
        if db == true then
            db = false
            script.Parent.Transparency = 1
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            local extra = 2 -- always add 1 extra to this such as if it gives +2 instead of 1, dont put 1, put 2.
            player.CharacterAdded:connect(function(char)
            if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(game.Players[char.Name].UserId, id) then
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + extra
            script.Sound:Play()
            wait(1)
            script.Parent.Transparency = 1
            wait(10) -- time before respawn
            db = true
            script.Parent.Transparency = 0
        else
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1 -- change 'Coins' to your currency name.
            script.Sound:Play()
            wait(1)
            script.Parent.Transparency = 1
            wait(10) -- time before respawn
            db = true
            script.Parent.Transparency = 0
        end
        end)
end  -- ending db or debounce
        end
        end)

Try this , i think the error was because you didn't end if db == true then

4 comments

0

If it doesn't work tell me, also if it drops an error i may need it

0

It does not work, after editing it, it seems to dropa error related to the if game:GetService etc, so it seems to be messed up there, if u can fix it tell me, otherwise ill try my best

0

Thanks a bit. I got this to work by changing some lines and connecting it to a true or false value if user owns game pass. but the end and debounce thing helped!

0

I'm very happy to hear that!

still dont work heres the full code


local id = 6488475 -- your gamepass id

local db = true
script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		if db == true then
			db = false
			script.Parent.Transparency = 1
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			local extra = 2 -- always add 1 extra to this such as if it gives +2 instead of 1, dont put 1, put 2.
			player.CharacterAdded:connect(function(char)
		    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(game.Players[char.Name].UserId, id) then
			player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + extra
			script.Sound:Play()
			wait(1)
			script.Parent.Transparency = 1
			wait(10) -- time before respawn
			db = true
			script.Parent.Transparency = 0
		else
			player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1 -- change 'Coins' to your currency name.
			script.Sound:Play()
			wait(1)
			script.Parent.Transparency = 1
			wait(10) -- time before respawn
			db = true
			script.Parent.Transparency = 0
		end
		end)
		end
		end




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