Is there anyway I can make this regen script to only work if the player has a gamepass? I’ve already tried this way but it doesn’t work. The only error I see is unknown global ‘player’
local MarketPlaceService = game:GetService("MarketplaceService")
local gamepassID = 129963361
local ownsGamepass = MarketPlaceService:UserOwnsGamePassAsync(Player.UserID, gamepassID)
model = script.Parent.Parent
regen = script.Parent
messageText = ""
message = Instance.new("Message")
message.Text = messageText
backup = model:clone()
enabled = true
function regenerate()
message.Parent = game.Workspace
regen:remove()
wait(1)
model = backup:clone()
model.Parent = game.Workspace
model:makeJoints()
message.Parent = nil
script.Disabled = true
script.Parent.BrickColor = BrickColor.new(26)--Black
wait(30)
script.Parent.BrickColor = BrickColor.new(104)--Purple
script.Disabled = false
end
function onHit(hit)
if (hit.Parent:FindFirstChild("Humanoid") ~= nil) and enabled then
if ownsGamepass then
regenerate()
else
MarketPlaceService.PromptGamePassPurchase(Player, gamepassID)
end
end
end
script.Parent.Touched:connect(onHit)
local MarketPlaceService = game:GetService("MarketplaceService")
local gamepassID = 129963361
model = script.Parent.Parent
regen = script.Parent
messageText = ""
message = Instance.new("Message")
message.Text = messageText
backup = model:clone()
enabled = true
function regenerate()
message.Parent = game.Workspace
regen:Remove()
wait(1)
model = backup:clone()
model.Parent = game.Workspace
model:makeJoints()
message.Parent = nil
script.Disabled = true
script.Parent.BrickColor = BrickColor.new(26)--Black
wait(30)
script.Parent.BrickColor = BrickColor.new(104)--Purple
script.Disabled = false
end
function onHit(hit)
if (hit.Parent:FindFirstChild("Humanoid") ~= nil) and enabled then
local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, gamepassID) then
regenerate()
else
MarketPlaceService:PromptGamePassPurchase(Player, gamepassID)
end
end
end
script.Parent.Touched:Connect(onHit)