script.Parent.Touched:Connect(function(hit)
local spawns = script.Parent.Parent.Spawns:GetChildren()
hit.Parent:FindFirstChild("HumanoidRootPart").Position = CFrame.new(math.random(1,#spawns))
end)
Thanks!
script.Parent.Touched:Connect(function(hit)
local spawns = script.Parent.Parent.Spawns:GetChildren()
hit.Parent:FindFirstChild("HumanoidRootPart").Position = CFrame.new(math.random(1,#spawns))
end)
Thanks!
You will use Vector as my new script here
--// Author: EnzoTDZ_YT
script.Parent.Touched:Connect(function(hit)
local spawns = script.Parent.Parent.Spawns:GetChildren()
-- hit.Parent:FindFirstChild("HumanoidRootPart").Position = CFrame.new(math.random(1,#spawns)) --// OLD
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(math.random(1,#spawns.Position))) --// NEW
end)
Still throws an error.
they may be a problem with your spawns
Math.random returns a number not an object value
I use MoveTo() seems to work fine for me
math.random() doesn't return 3 numbers
I don’t know how to index a object value to a string value but maybe try it now
It says line 3 is a bad argument (interval is empty)
It says line 3 is a bad argument (interval is empty)
It says line 3 is a bad argument (interval is empty)
Is the script in the brick? it is supposed be in the brick as its first child
script.Parent.Touched:Connect(function(hit)
local spawns = script.Parent.Parent.Spawns:GetChildren()
local ChosenSpawn = spawns[math.random(1,#spawns)]
local Player = hit.Parent:FindFirstChild("HumanoidRootPart")
if Player then
Player.CFrame = ChosenSpawn.CFrame
end
end)
This should work
It says line 3 is a bad argument (interval is empty)
That means that #spawns < 1.
I used this for the alvinblox tutorial and it worked.
script.Parent.Touched:Connect(function(hit)
local spawns = script.Parent.Parent.Spawns:GetChildren()
hit.Parent:FindFirstChild("HumanoidRootPart").Position = CFrame.new(math.random(1,#spawns).Position)
end)
Maybe this will work. Try it! <3
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
Error: CFrame.new(math.random(1,#spawns))
Could you possibly mean CFrame.new(spawns[math.random(1, #spawns)].Position)?