I've recently just started to learn the basics of Lua, however when I run this script, the second function does not seem to work. The first works just fine and destroys when I touch it, but it does not move randomly, as I have tried to attempt in the second function.
Model = game.Workspace.Part function destroy() game.Workspace.Part:Destroy() end script.Parent.Touched:connect(destroy) function move() Model:MoveTo(math.random()) wait(2) repeat until script.Parent.Touched end game.Players.PlayerAdded:connect(move)
MoveTo is a function that takes a Vector3. math.random is a function that returns a single number. So, MoveTo is expecting 3 numbers, but you're passing 1 into it. Try this:
local Model = game.Workspace.Part function destroy() game.Workspace.Part:Destroy() end script.Parent.Touched:connect(destroy) function move() local touched Model.Tocuhed:connect(function(hit) if hit and hit.Parent:FindFirstChild("Humanoid") then touched = true end end) while not touched do Model.Position = Vector3.new(math.random(),math.random(),math.random())*10 wait(1) end end game.Players.PlayerAdded:connect(move)
Also, the line repeat until script.Parent.Touched
does nothing for your code, so I suggest removing that.
EDIT: MoveTo was not even applicable here.
EDIT 2: Made it loop.