Hello! I am very new when it comes to any kind of scripting, so I apologize in advance if I sound stupid and none of you guys know what I am talking about and if I am too vague. As of lately I have encountered a problem whilst working with someone on a project for a bank robbery system. When we finally finished and imported what we had made into our main game it would for some odd reason not work as intended compared to our original test place. I compared both games with almost everything and they still seem to not work and behave differently despite there being no differences whatsoever. When looking at the outputs, they seem to give off different results however.
What is supposed to happen in the original version is that you walk through the âvault doorâ into a room that is supposed to give you approximately 100 Cash once you touch the stack of money.
Once you equip the cash, you must walk through the same âVault doorâ which is the slightly transparent brick, and then once you go through the door you must walk 550 studs away from the vault door for it to award you the cash in the leaderboard.
Looking at the output, it shows how much studs you have walked so far from the vault door, which looks like this:

Now, let me get to the root of the problem! For some reason when I test it in the main game, right when I walk through the door once I equip the cash, instead of it waiting for me to walk 550 studs away from the door, it immediately awards me the cash. I noticed that when I look at the output, it is much different and doesnât count the amount of steps I have walked from the vault door, but instead the approximate position of the vault door itself. Here is what that looks like in the output:

As you can see, its just one small thing. When I went to the source of it, apparently the script in the âvault doorâ from line 45 and down have something to do with it. Here is a screenshot:
So, I am not completely sure what to do, and I had a friend work on this and he is dumbfounded as to why it is not working when I inserted everything from our test game into my main game, but I hope one of you out there can hopefully decipher this because I honestly do not know what to do nor what I am looking at, the only thing I could think of is that it is not syncing or something, but I have no idea.
Oh, and as requested, here is the full code:
local disTanceText2 = 0
local function onTouch(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if script.Parent:FindFirstChild(hit.Parent.Name) then
return end
if script.Parent.Parent.Bills.Bank.Value == true then
return end
local Player = game.Players:FindFirstChild(hit.Parent.Name)
playerName = hit.Parent.Name
local part = Instance.new("Part")
part.Anchored = true
part.Parent = script.Parent
part.Name = hit.Parent.Name
part.Position = script.Parent.Position
part.CanCollide = false
part.Transparency = 1
script.Parent.Parent.Bills.Bank.Value = true
end
showGui()
end
function showGui()
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
if player.Team == game:GetService("Teams").Police then
local clone = game.ReplicatedStorage.BankRob:Clone()
clone.Parent = player.PlayerGui
end
end
distanceCheck()
end
function distanceCheck()
repeat
local Player = game.Players:FindFirstChild(playerName)
if game.Workspace.Monet.VaultEnter:FindFirstChild(playerName) then
local disTance = Player:DistanceFromCharacter(Vector3.new(game.Workspace.Monet.VaultEnter:FindFirstChild(playerName).Position))
local disTanceText1 = math.floor(disTance)
disTanceText2 = disTanceText1
end
wait(0.1)
print(disTanceText2)
until disTanceText2 > 550
endFunction()
end
function endFunction()
if game.Workspace.Monet.VaultEnter:FindFirstChild(playerName) then
local part = game.Workspace.Monet.VaultEnter:FindFirstChild(playerName)
part:Destroy()
end
disTanceText2 = 0
local Player = game.Players:FindFirstChild(playerName)
Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + Player.robInfo.cashTaken.Value
Player.robInfo.cashTaken.Value = 0
Player.PlayerGui.BankGui.Main.Visible = false
script.Parent.Parent.Bills.CoolDown.CoolDownStart:FireClient(Player)
script.Parent.Parent.Bills.Bank.Value = false
script.Parent.Script.Disabled = true
end
script.Parent.Touched:Connect(onTouch)
UPDATE:
So we have decided to change it up a little bit and we are now making it so when you take the Cash, instead of walking 550 studs away you must instead drop off the cash to be awarded it in the leader stats. The new problem we are having now is that once you walk up to the brick that awards you the cash at the drop off, it is not awarding you the cash nor getting rid of the GUI that says how much cash you have. Here is the updated code:
local disTanceText2 = 0
local function onTouch(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if script.Parent:FindFirstChild(hit.Parent.Name) then
return end
local Player = game.Players:FindFirstChild(hit.Parent.Name)
game.ReplicatedStorage.NameCheck:FireClient(Player)
game.ReplicatedStorage.NameCheck.OnServerEvent:Connect(function(Player, Name)
playerName = Name
print(playerName .. Name)
end)
playerName = hit.Parent.Name
local part = Instance.new("Part")
part.Parent = script.Parent
print(playerName)
part.Name = hit.Parent.Name
part.Position = script.Parent.Position
part.Transparency = 1
script.Parent.Parent.Bills.Bank.Value = true
end
showGui()
end
function showGui()
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
if player.Team == game:GetService("Teams").Police then
local clone = game.ReplicatedStorage.BankRob:Clone()
clone.Parent = player.PlayerGui
end
end
end
function robberCheck(hit)
if hit.Parent.Name == playerName then
endFunction()
end
end
function endFunction()
if game.Workspace.Monet.VaultEnter:FindFirstChild(playerName) then
local part = game.Workspace.Monet.VaultEnter:FindFirstChild(playerName)
part:Destroy()
end
disTanceText2 = 0
local Player = game.Players:FindFirstChild(playerName)
Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + Player.robInfo.cashTaken.Value
Player.robInfo.cashTaken.Value = 0
Player.PlayerGui.BankGui.Main.Visible = false
playerName = ""
--script.Parent.Parent.Bills.CoolDown.CoolDownStart:FireClient(Player)
end
script.Parent.Touched:Connect(function(hit)
if script.Parent.Parent.Bills.Bank.Value == true then
return end
script.Parent.Parent.Bills.Bank.Value = true
onTouch(hit)
end)
script.Parent.Parent.DP.Touched:Connect(robberCheck)
Once again I hope one of you out there can decipher this and help us out!