We would like to use parameters and debounce
We use the parameters to access the character
And we use debounce so it wouldn't do it too many times(Since doing a normal part.Touched event, it would be many times: LeftLeg,RightLeg)
local part = script.Parent
local model = part.Parent.Parent
local spawns = {
model.Spawns.Spawn1.Position;
model.Spawns.Spawn2.Position;
model.Spawns.Spawn3.Position;
model.Spawns.Spawn4.Position;
model.Spawns.Spawn5.Position;
model.Spawns.Spawn6.Position;
model.Spawns.Spawn7.Position;
model.Spawns.Spawn8.Position;
model.Spawns.Spawn9.Position
}
local debounce = false
part.Touched:Connect(function(hit)
if hit and hit.Parent and debounce == false then
debounce = true
local char = hit.Parent
local torso = char:FindFirstChild("HumanoidRootPart")
for amount,obj in pairs(spawns) do
math.randomseed(tick())
local randomSpawn = spawns[math.random(1,amount) ]
torso.CFrame = CFrame.new(randomSpawn)
end
else
print("hit and hit.Parent is nil")
end
wait()
if debounce == true then
debounce = false
end
end)
As you can see, we have replaced the variable into a table
Its more efficient.
Plus you were only looking at the index of the spawns:GetChildren() not the object
Hopefully this helped
1 comment
Ever tried something very useful called "print debugging"?