I was making a buy area system for my simulator game but it takes away way too much money and I figured out why, can anyone help me find a solution? (Print statement marks where it is wrong)
for i, v in pairs(teleporters:GetChildren()) do
if v:IsA("Part") then
v.Touched:Connect(function(hit)
local humanoidRootPart = hit.Parent:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
local char = hit.Parent
local player = game.Players:GetPlayerFromCharacter(char)
if player.Areas:FindFirstChild(player.CurrentWorld.Value):FindFirstChild(v.Name).Value == true then
humanoidRootPart.CFrame = floors:FindFirstChild(v.Name.."Floor").CFrame + Vector3.new(0, 10, 0)
else
print("Hi") --Prints the more I step on the part
eventFolder.AskToBuy:FireClient(player, floors:FindFirstChild(v.Name.."Floor").Cost.Value, v.Name)
end
end
end)
end
end
It still does not work, it does it way less but still it wont work
local debouce = false
for i, v in pairs(teleporters:GetChildren()) do
if v:IsA("Part") then
v.Touched:Connect(function(hit)
local humanoidRootPart = hit.Parent:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
local char = hit.Parent
local player = game.Players:GetPlayerFromCharacter(char)
if player.Areas:FindFirstChild(player.CurrentWorld.Value):FindFirstChild(v.Name).Value == true then
humanoidRootPart.CFrame = floors:FindFirstChild(v.Name.."Floor").CFrame + Vector3.new(0, 10, 0)
else
if debouce == false then
debouce = true
eventFolder.AskToBuy:FireClient(player, floors:FindFirstChild(v.Name.."Floor").Cost.Value, v.Name)
wait(1)
debouce = false
end
end
end
end)
end
end
The debounce system is the right way to go here, not entirely sure if this will work but try this
local debouce = false
for i, v in pairs(teleporters:GetChildren()) do
if v:IsA("Part") then
v.Touched:Connect(function(hit)
local humanoidRootPart = hit.Parent:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
local char = hit.Parent
local player = game.Players:GetPlayerFromCharacter(char)
if player.Areas:FindFirstChild(player.CurrentWorld.Value):FindFirstChild(v.Name).Value == true then
humanoidRootPart.CFrame = floors:FindFirstChild(v.Name.."Floor").CFrame + Vector3.new(0, 10, 0)
else
if debounce == false then
debounce = true
eventFolder.AskToBuy:FireClient(player, floors:FindFirstChild(v.Name.."Floor").Cost.Value, v.Name)
end
end
end
end)
v.TouchEnded:Connect(function()
task.wait(.5)
debounce = false
end)
end
end