Okay so, I’m making a game and I want there to be a safe zone. I don’t want a safe zone you’re probably thinking, I want one where it keeps a force field around the player until off the brick. If you can tell me the script or something i can watch that would be amazing.
-- a function that returns true if the player is standing on or above the part
local function isStandingOn(position, brick)
local v3 = brick.CFrame:PointToObjectSpace(position)
return (math.abs(v3.X) <= brick.Size.X / 2)
and (math.abs(v3.Z) <= brick.Size.Z / 2)
and (v3.Y >= 0)
end
local runService = game:GetService("RunService")
local players = game:GetService("Players")
-- every physics frame
runService.Heartbeat:Connect(function()
for _, player in ipairs(players:GetPlayers()) do
-- check every player for a torso and see if they are standing on the part
local hrp = (player.Character ~= nil) and player.Character:FindFirstChild("HumanoidRootPart")
if (hrp) then
-- add or remove a forcefield depending on where they are
local ff = player.Character:FindFirstChildOfClass("ForceField")
if (isStandingOn(hrp.Position, script.Parent)) then
if (ff == nil) then
Instance.new("ForceField").Parent = player.Character
end
else
if (ff ~= nil) then
ff:Destroy()
end
end
end
end
end)