Trying To make a script that teleports you, opens UI and awards you leaderstats depending on if you have a gamepass or not.
So here it is.
local part = script.Parent
local deb = false
local gamepass1 = 18141166
local gamepass2 = 18141180
local marketplaceService = game:GetService('MarketplaceService')
--- Gamepass 1 is wins
--- Gamepass 2 is coins
local debtime = 1
part.Touched:Connect(function(hit)
local touchPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
local GUI = touchPlayer.PlayerGui.Winnerpartthing
local teleporter = script.Parent.Parent.Parent.Lobby.InvisiblePart
function WinningStuff(CoinsNum,WinsNum)
hit.Parent.HumanoidRootPart.CFrame = teleporter.CFrame
touchPlayer.leaderstats.Wins.Value += WinsNum
touchPlayer.leaderstats.Coins.Value += CoinsNum
GUI.Coins.MainText = "+"..CoinsNum
GUI.Wins.MainText = "+"..WinsNum
GUI.Coins.Visible = true
GUI.Wins.Visible = true
wait(4)
GUI.Coins.Visible = false
GUI.Wins.Visible = false
wait(debtime)
deb = false
end
if not touchPlayer or deb then return end
deb = true
if marketplaceService:UserOwnsGamePassAsync(touchPlayer.UserId, gamepass1) and marketplaceService:UserOwnsGamePassAsync(touchPlayer.UserId, gamepass2) then
WinningStuff(100,2) --- Both Gamepasses
elseif marketplaceService:UserOwnsGamePassAsync(touchPlayer.UserId, gamepass1)then
WinningStuff(50,2) -- Just 2x Wins
elseif marketplaceService:UserOwnsGamePassAsync(touchPlayer.UserId, gamepass2) then
WinningStuff(100,1) -- Just x2 Coins
else
WinningStuff(50,1) -- No Gamepasses
end
end)
It is giving out this error.