Minigames script won't work

Hello, I am a scripter an I have been using some tutorials, as I am fairly new. I have only been working with lua for 2-3 years. If you can please explain to me why this script won’t work (I have looked over, my spelling and where the places are is right) and if possible, could you fix it?

script.Parent.Touched:Connect(function(hit)
	if hit~= nil then
		if hit.Parent~= nil then
			if hit.Parent.Humanoid.Health~= 0 then
				local player = game.Players:GetPlayerFromCharacter(hit.Parent)
				player.Settings.Win.Value = true
				local spawns = game.Workspace.Spawns:GetChildren()
				hit.Parent.HumanoidRootPart.CFrame = spawns[math.random(1,#spawns)].CFrame + Vector3.new(0,3,0)
			end
		end
	end
end)

I’m pretty sure this is where the error lies. You’re doing math operations with 2 different values, which throws an error. You should do:

hit.Parent.HumanoidRootPart.CFrame = spawns[math.random(1,#spawns)].CFrame * CFrame.new(0,3,0)

Ok, thank you for the tip! I will tell you if it works!

It worked! Thank you so much! 30chars

1 Like