For some reason when ever the player enters the safe zone and like the bubble is growing as they enter their animation will freeze in place on the other players screen
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local bubbleTemplate = ReplicatedStorage:WaitForChild("SpawnBubble")
local BubbleButtons = ReplicatedStorage:WaitForChild("BubbleButtons")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local activeBubbles = {}
-- Define your Bubble GamePass ID
local BubbleGamePassID = 951306815 -- Replace with your actual Bubble Game Pass ID
-- Store the Bubble GamePass ownership status of players
local BubblePassOwners = {}
-- Function to check if a player owns the Bubble GamePass asynchronously
local function checkBubblePassOwnership(player)
local success, hasGamePass = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, BubbleGamePassID)
end)
if success then
BubblePassOwners[player.UserId] = hasGamePass
if hasGamePass then
print(player.Name .. " owns the Bubble GamePass.")
end
else
warn("Error checking Bubble GamePass ownership for player " .. player.Name)
BubblePassOwners[player.UserId] = false
end
end
-- Listen for Game Pass purchase event and add to Bubble Pass Owners if purchased
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, purchasedGamePassID, wasPurchased)
if wasPurchased and purchasedGamePassID == BubbleGamePassID then
BubblePassOwners[player.UserId] = true
print(player.Name .. " has purchased the Bubble GamePass.")
end
end)
-- Function to check if a player is inside the safe zone
local function isPlayerInsideZone(player)
local character = player.Character
if not character then return false end
local rootPart = character:FindFirstChild("HumanoidRootPart")
if not rootPart then return false end
local zonePosition = safeZone.Position
local zoneSize = safeZone.Size
return rootPart.Position.X > (zonePosition.X - zoneSize.X / 2) and rootPart.Position.X < (zonePosition.X + zoneSize.X / 2) and
rootPart.Position.Y > (zonePosition.Y - zoneSize.Y / 2) and rootPart.Position.Y < (zonePosition.Y + zoneSize.Y / 2) and
rootPart.Position.Z > (zonePosition.Z - zoneSize.Z / 2) and rootPart.Position.Z < (zonePosition.Z + zoneSize.Z / 2)
end
-- Function to clean up old bubbles
local function cleanUpBubble(player)
if activeBubbles[player] then
if activeBubbles[player]:FindFirstChild("WeldConstraint") then
activeBubbles[player].WeldConstraint:Destroy()
end
activeBubbles[player]:Destroy()
activeBubbles[player] = nil
end
-- Remove the ForceField if it exists
if player.Character then
local forceField = player.Character:FindFirstChild("ForceField")
if forceField then
forceField:Destroy()
end
end
end
-- Function to adjust bubble size smoothly
local function adjustBubbleSize(bubble, targetSize)
if not bubble then return end
-- Make sure the target size is not too big and doesn't interfere with animations
targetSize = targetSize or Vector3.new(1, 1, 1)
-- Smooth size transition
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local goal = {Size = targetSize}
local tween = TweenService:Create(bubble, tweenInfo, goal)
tween:Play()
end
-- Function to create a bubble for the player
local function createBubbleForPlayer(player)
cleanUpBubble(player)
local character = player.Character
if not character then return end
local rootPart = character:WaitForChild("HumanoidRootPart", 3)
if not rootPart then return end
-- Create and weld the bubble
local bubble = bubbleTemplate:Clone()
bubble.Parent = workspace
bubble.Name = player.Name .. "_Bubble"
bubble.Size = Vector3.new(1, 1, 1) -- Initial size
bubble.CanCollide = false -- Prevent collision issues
bubble.CFrame = rootPart.CFrame
-- Weld bubble to player
local weld = Instance.new("WeldConstraint")
weld.Part0 = rootPart
weld.Part1 = bubble
weld.Parent = bubble
activeBubbles[player] = bubble
end
-- Function to limit player velocity
local function limitPlayerVelocity(player)
local character = player.Character
if not character then return end
local rootPart = character:FindFirstChild("HumanoidRootPart")
if not rootPart then return end
local velocity = rootPart.Velocity
local maxSpeed = 5000 -- Max allowable speed
if velocity.Magnitude > maxSpeed then
rootPart.Velocity = velocity.Unit * maxSpeed
end
end
-- Function to update the bubble color
local function updateBubbleColor(bubble, color)
if bubble then
if color == "Red" then
bubble.Color = Color3.fromRGB(255, 0, 0)
elseif color == "Green" then
bubble.Color = Color3.fromRGB(0, 255, 0)
elseif color == "Blue" then
bubble.Color = Color3.fromRGB(0, 0, 255)
elseif color == "Pink" then
bubble.Color = Color3.fromRGB(255, 0, 255)
elseif color == "Orange" then
bubble.Color = Color3.fromRGB(255, 165, 0)
elseif color == "Cyan" then
bubble.Color = Color3.fromRGB(0, 255, 255)
elseif color == "Purple" then
bubble.Color = Color3.fromRGB(128, 0, 128)
elseif color == "Black" then
bubble.Color = Color3.fromRGB(0, 0, 0)
elseif color == "White" then
bubble.Color = Color3.fromRGB(255, 255, 255)
end
end
end
-- Listen for button click events from the client
BubbleButtons.OnServerEvent:Connect(function(player, color)
print("Button clicked: " .. color)
-- Check if the player owns the Bubble GamePass before proceeding
if not BubblePassOwners[player.UserId] then
-- If the player doesn't own the GamePass, prompt them to purchase it
MarketplaceService:PromptGamePassPurchase(player, BubbleGamePassID)
print(player.Name .. " is prompted to buy the GamePass.")
return
end
-- Handle the bubble color change if the player owns the GamePass
local bubble = activeBubbles[player]
if bubble then
updateBubbleColor(bubble, color)
end
end)
-- Update bubble transparency and size
local function updateBubbleTransparencyAndSize()
for player, bubble in pairs(activeBubbles) do
if bubble and player.Character then
local isInside = isPlayerInsideZone(player)
-- Adjust bubble size when inside or outside the safe zone
local targetSize = isInside and Vector3.new(8.5, 8.5, 8.5) or Vector3.new(1, 1, 1)
adjustBubbleSize(bubble, targetSize)
-- Set bubble transparency based on zone status
bubble.Transparency = isInside and 0.05 or 1
end
end
end
-- Player Added Event
game.Players.PlayerAdded:Connect(function(player)
-- Check GamePass when the player joins (only once)
checkBubblePassOwnership(player)
-- Ensure the player gets their bubble upon character addition
player.CharacterAdded:Connect(function()
wait(0.5) -- Ensure character is fully loaded
createBubbleForPlayer(player)
end)
end)
-- Player Removing Event
game.Players.PlayerRemoving:Connect(function(player)
cleanUpBubble(player)
end)
-- Update bubble transparency, size, and position every frame
game:GetService("RunService").Heartbeat:Connect(function()
for _, player in pairs(game.Players:GetPlayers()) do
if player.Character then
limitPlayerVelocity(player) -- Prevent excessive speed
updateBubbleTransparencyAndSize() -- Update bubble size and transparency
end
end
end)