I’m making a robbery system and everything is working normally, except when you get caught in the store after the timer runs out.
When the player is inside the store after the timer runs out the player gets teleported outside of the store but it will occasionally teleport you outside the store even if you’re not inside the store. Obviously this could be a problem if you’re across the map and you just randomly get teleported to a Jewelry store.
Code which teleports player:
RUN_SERVICE.Heartbeat:Connect(function()
local parts = game.Workspace:GetPartBoundsInBox(area.CFrame, area.Size)
for i, v in pairs(parts) do
if v.Parent:FindFirstChild("Humanoid") then
if SS.Robbery.Value == false then
v.Parent.HumanoidRootPart.Position = game.Workspace:FindFirstChild("rob").Position
break
end
end
end
end)
Full Code
--//Constants
local ROBBERY_TIME = 5
local COOLDOWN = 10
local JEWEL_PARENT = game.Workspace
local SS = game:GetService("ServerStorage")
local RS = game:GetService("ReplicatedStorage")
local RUN_SERVICE = game:GetService("RunService")
--//Variables
local prompt = script.Parent
local glass = game.Workspace:FindFirstChild("glass")
local area = game.Workspace:FindFirstChild("area")
--//Events
prompt.Triggered:Connect(function(plr)
glass.Transparency = 1
glass.CanCollide = false
prompt.Enabled = false
SS.Robbery.Value = true
plr.PlayerGui.RobUI.Enabled = true
task.spawn(function()
wait(ROBBERY_TIME)
glass.Transparency = .4
glass.CanCollide = true
SS.Robbery.Value = false
plr.PlayerGui.RobUI.Enabled = false
for i, v in pairs(JEWEL_PARENT:GetChildren()) do
if v.Name == "Jewel" then
v:FindFirstChild("ProximityPrompt").Enabled = false
end
end
wait(COOLDOWN)
prompt.Enabled = true
end)
for i, v in pairs(JEWEL_PARENT:GetChildren()) do
if v.Name == "Jewel" then
v:FindFirstChild("ProximityPrompt").Enabled = true
v.CanCollide = true
v.Transparency = 0
end
end
task.spawn(function()
for i = ROBBERY_TIME, 0, -1 do
plr.PlayerGui.RobUI.Frame.TextLabel.Text = "You have "..i.." seconds to rob"
wait(1)
end
end)
end)
RUN_SERVICE.Heartbeat:Connect(function()
local parts = game.Workspace:GetPartBoundsInBox(area.CFrame, area.Size)
for i, v in pairs(parts) do
if v.Parent:FindFirstChild("Humanoid") then
if SS.Robbery.Value == false then
v.Parent.HumanoidRootPart.Position = game.Workspace:FindFirstChild("rob").Position
break
end
end
end
end)
I’m a little new to the method :GetPartBoundsInBox
so if anyone could help that’d be great!
Thanks,
dza
EDIT: Forgot to show video lol