I am trying to have it so that when the player is inside the safe zone aka this big box they have this spawnbubble around them thats locked to them only while in the zone
The issue is whenever the player walks in the safe zone they are briefly teleported back to the spot they walked in on and while in the safe zone the players walk animation is kinda stiff.
I tried using motor6d or cframe position updating but they both do the same thing well cframe position updatng doesnt but the bubble follows the player very laggily.
local safeZone = workspace:WaitForChild("SafeZone") -- Your box-shaped SafeZone part
local ReplicatedStorage = game.ReplicatedStorage
local bubbleEvent = ReplicatedStorage:WaitForChild("BubbleEvent") -- RemoteEvent for bubble control
local bubbleTemplate = ReplicatedStorage:WaitForChild("SpawnBubble") -- The original bubble mesh in ReplicatedStorage
-- 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 humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if not humanoidRootPart then return false end
-- Check if the player's HumanoidRootPart is inside the SafeZone part
local zonePosition = safeZone.Position
local zoneSize = safeZone.Size
return humanoidRootPart.Position.X > (zonePosition.X - zoneSize.X / 2) and humanoidRootPart.Position.X < (zonePosition.X + zoneSize.X / 2) and
humanoidRootPart.Position.Y > (zonePosition.Y - zoneSize.Y / 2) and humanoidRootPart.Position.Y < (zonePosition.Y + zoneSize.Y / 2) and
humanoidRootPart.Position.Z > (zonePosition.Z - zoneSize.Z / 2) and humanoidRootPart.Position.Z < (zonePosition.Z + zoneSize.Z / 2)
end
-- Table to track active bubbles
local activeBubbles = {}
-- Function to create a bubble for the player inside the safe zone
local function createBubbleForPlayer(player)
local character = player.Character
if not character then return end
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if not humanoidRootPart then return end
-- Create the bubble and place it near the player's HumanoidRootPart
local bubble = bubbleTemplate:Clone()
bubble.Parent = workspace
bubble.Name = player.Name .. "_Bubble"
bubble.Size = Vector3.new(8.5, 8.5, 8.5)
-- Set the bubble's initial position to the player's HumanoidRootPart position
bubble.CFrame = humanoidRootPart.CFrame
-- Create a WeldConstraint to attach the bubble to the player's HumanoidRootPart
local weld = Instance.new("WeldConstraint")
weld.Parent = bubble
weld.Part0 = humanoidRootPart
weld.Part1 = bubble
-- Add to activeBubbles table
activeBubbles[player] = bubble
end
-- Handle damage prevention, ForceField, and bubble display
game:GetService("RunService").Heartbeat:Connect(function()
for _, player in pairs(game.Players:GetPlayers()) do
local character = player.Character
if character then
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
local forceField = character:FindFirstChildOfClass("ForceField") -- Look for existing ForceField
if humanoidRootPart then
-- Check if the player is inside the safe zone
if isPlayerInsideZone(player) then
-- Create ForceField if not present
if not forceField then
forceField = Instance.new("ForceField")
forceField.Parent = character
forceField.Visible = false -- Make the ForceField invisible
end
-- Check if the bubble is already created for this player
local bubble = activeBubbles[player]
if not bubble then
-- Create the bubble
createBubbleForPlayer(player)
-- Fire event to clients to show the bubble
bubbleEvent:FireAllClients(player, true)
end
else
-- Remove ForceField and bubble when player exits the safe zone
if forceField then
forceField:Destroy()
end
-- Destroy the bubble
local bubble = activeBubbles[player]
if bubble then
bubble:Destroy()
activeBubbles[player] = nil
-- Fire event to clients to hide the bubble
bubbleEvent:FireAllClients(player, false)
end
end
end
end
end
end)
Any help is appreciated